Inheritance: System.Data.Common.DbCommand, ICloneable, IDbCommand
Exemple #1
1
        private void lc(object sender, MouseEventArgs e)
        {
            c.Open();
            DataSet ds = new DataSet();
            string query = "select ID,pname,bill,pbill from pdetails where [email protected] ";
            OleDbCommand cmd = new OleDbCommand(query, c);
            cmd.Parameters.Add("@bc", OleDbType.Date).Value = dateTimePicker1.Value.Date;
            OleDbDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            /*ds.Tables.Add(dt);
            OleDbDataAdapter da = new OleDbDataAdapter();
            da.Fill(dt);*/
            dataGridView1.DataSource = dt.DefaultView;
            c.Close();
            try
            {
                c.Open();
                String str = @"SELECT SUM(pbill) FROM pdetails WHERE [email protected];";

                OleDbCommand comm2 = new OleDbCommand(str, c);
                comm2.Parameters.Add("@bb", OleDbType.Date).Value = dateTimePicker1.Value.Date;
                bill = Convert.ToDouble(comm2.ExecuteScalar());

                label3.Text = bill.ToString() + "/-";
            }
            catch(Exception ex)
            {
                MessageBox.Show("selected date miss match");
                c.Close();
            }
                c.Close();
        }
        public static int SaveRecord(string sql)
        {
            const int rv = 0;
            try
            {
                string connectionString = ConfigurationManager.ConnectionStrings["LA3Access"].ConnectionString;
                using (var conn = new OleDbConnection(connectionString))
                {
                    conn.Open();
                    var cmGetID = new OleDbCommand("SELECT @@IDENTITY", conn);
                    var comm = new OleDbCommand(sql, conn) { CommandType = CommandType.Text };
                    comm.ExecuteNonQuery();

                    var ds = new DataSet();
                    var adapt = new OleDbDataAdapter(cmGetID);
                    adapt.Fill(ds);
                    adapt.Dispose();
                    cmGetID.Dispose();

                    return int.Parse(ds.Tables[0].Rows[0][0].ToString());

                }
            }
            catch (Exception)
            {
            }
            return rv;
        }
Exemple #3
0
        public void FillCombo()
        {
            try
            {

                con = new OleDbConnection(cs);
                con.Open();
                string ct = "select RTRIM(CategoryName) from Category order by CategoryName";
                cmd = new OleDbCommand(ct);
                cmd.Connection = con;
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    cmbCategory.Items.Add(rdr[0]);
                }
                con.Close();
                con = new OleDbConnection(cs);
                con.Open();
                string ct1 = "select RTRIM(CompanyName) from Company order by CompanyName";
                cmd = new OleDbCommand(ct1);
                cmd.Connection = con;
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    cmbCompany.Items.Add(rdr[0]);
                }
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
0
        /// <summary>
        /// Reads the selected file and places the contents into a DataTable.
        /// </summary>
        /// <returns>Datatable of students in file</returns>
        public DataTable ReadFile()
        {
            DataTable data = new DataTable();

            try
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = string.Format("SELECT * from [{0}]", file.Name);
                    con.Open();

                    using (dr = cmd.ExecuteReader())
                    {
                        data.Load(dr);
                    }
                }
            }
            catch (OleDbException oExe)
            {
                Debug.WriteLine(oExe.Message);
            }
            finally
            {
                con.Close();
            }

            return data;
        }
Exemple #5
0
    public int EnterToSite(UserDetails userDetails)//בודק על פי האימייל והסיסמא האם המשתשמש שמנסה להיכנס לאתר קיים או לא
    {
        OleDbCommand myCmd = new OleDbCommand("CheckIfUserExist", myConnection);
        myCmd.CommandType = CommandType.StoredProcedure;

        OleDbParameter objParam;

        objParam = myCmd.Parameters.Add("@Email", OleDbType.BSTR);
        objParam.Direction = ParameterDirection.Input;
        objParam.Value = userDetails.email;

        objParam = myCmd.Parameters.Add("@Password", OleDbType.BSTR);
        objParam.Direction = ParameterDirection.Input;
        objParam.Value = userDetails.password;

        int x = 0;
        try
        {
            myConnection.Open();
            x = (int)myCmd.ExecuteScalar();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            myConnection.Close();
        }
        return x;

    }
        protected void datefilterPlanMeal_DayRender(object sender, DayRenderEventArgs e)
        {
            OleDbCommand command = new OleDbCommand("SELECT * FROM PlannedMeal WHERE UserDataID = " + userID + " ORDER BY CreatedDate DESC", myConnection);

            OleDbDataReader dr = command.ExecuteReader();
            // Read DataReader till it reaches the end
            while (dr.Read() == true)
            {
                // Assign the Calendar control dates
                // already contained in the database
                //datefilterPlanMeal.SelectedDates.Add((DateTime)dr["CreatedDate"]);
                if (e.Day.Date == (DateTime)dr["CreatedDate"])
                {
                    e.Cell.BackColor = System.Drawing.Color.Silver;
                }
            }
            if (e.Day.IsSelected)
            {
                e.Cell.BackColor = System.Drawing.ColorTranslator.FromHtml("#4db6ac");
                e.Cell.ForeColor = System.Drawing.Color.White;
            }

            // Close DataReader
            dr.Close();
        }
Exemple #7
0
 private void fill_form(string p_id)
 {
     String strQuery = String.Empty;
     OleDbConnection sqlConn = new OleDbConnection();
     OleDbCommand sqlComm = new OleDbCommand();
     OleDbDataReader sqlRead;// = new OleDbDataReader();
     DateTime strReturn = DateTime.Now;
     //
     sqlConn.ConnectionString = PCPUB.m_oledb_connection.ToString();
     sqlConn.Open();
     //
     strQuery = String.Empty;
     strQuery += " SELECT";
     strQuery += " [yarn_count_id],";
     strQuery += " [yarn_count_name]";
     strQuery += " FROM [tis_yarn_count]";
     strQuery += " WHERE [yarn_count_id] = '" + p_id + "'";
     //
     sqlComm.Connection = sqlConn;
     sqlComm.CommandText = strQuery.ToString();
     sqlRead = sqlComm.ExecuteReader();
     //
     if (sqlRead.Read())
     {
         txt_yarn_count_id.Text = sqlRead["yarn_count_id"].ToString();
         txt_yarn_count_name.Text = sqlRead["yarn_count_name"].ToString();
     }
     //
     sqlRead.Close();
     sqlConn.Close();
     sqlRead.Dispose();
     sqlComm.Dispose();
     sqlConn.Dispose();
 }
    public string LoadContain()
    {
        if (Request.QueryString["CourseId"] == null)
        {
            return string.Empty;
        }

        string ThePath = string.Empty;
        string RetData = string.Empty;
        using (OleDbConnection Con = new OleDbConnection(constr))
        {
            OleDbCommand cmd = new OleDbCommand(String.Format("SELECT TOP 1 DataPath FROM CoursenotimeDataPath WHERE CourseId = {0}", Request.QueryString["CourseId"]), Con);
            try
            {
                Con.Open();
                ThePath = cmd.ExecuteScalar().ToString();
                //if (ThePath != string.Empty)
                //    ThePath = MapPath(DB.CourseNoTimeFileDir + ThePath);
                ThePath = DB.CourseNoTimeFileDir + ThePath;

                TextReader TR = new StreamReader(ThePath);
                RetData = TR.ReadToEnd();
                TR.Close();
                TR.Dispose();

            }
            catch (Exception ex)
            {
                RetData = ex.Message;
            }
            Con.Close();
        }

        return HttpUtility.HtmlDecode(RetData);
    }
    protected void btnAddBag_Click(object sender, EventArgs e)
    {
        try
        {

            OleDbConnectionStringBuilder sb = new OleDbConnectionStringBuilder();
            sb.Provider = "Microsoft.ACE.OLEDB.12.0";
            sb.DataSource = Server.MapPath("/vedb01/uploads/db1.accdb");
            OleDbConnection conn = new OleDbConnection(sb.ConnectionString);
            conn.Open();
            string insertQuery = "insert into Bag ( [BagName], [Supplier], [Color], [Category], [Price], [Description]) values (@name ,@supplier ,@color ,@category ,@price ,@description)";
            OleDbCommand com = new OleDbCommand(insertQuery, conn);
            com.Parameters.AddWithValue("@name", txtBagName.Text);
            com.Parameters.AddWithValue("@supplier", txtSupplier.Text);
            com.Parameters.AddWithValue("@color", txtColor.Text);
            com.Parameters.AddWithValue("@category", txtCategory.Text);
            com.Parameters.AddWithValue("@price", txtPrice.Text);
            com.Parameters.AddWithValue("@description", txtDescription.Text);

            com.ExecuteNonQuery();

            lblMessage.Text = "The bag was added successfully " + txtBagName.Text + " !";

            conn.Close();
        }
        catch (Exception ex)
        {
            Response.Write("Error: " + ex.ToString());
            lblMessage.Text = "Error" + txtBagName.Text + " !";
        }
    }
Exemple #10
0
 /// <summary>
 /// 执行多条SQL语句,实现数据库事务。
 /// </summary>
 /// <param name="SQLStringList">多条SQL语句</param>		
 public static void ExecuteSqlTran(ArrayList SQLStringList)
 {
     using (OleDbConnection conn = new OleDbConnection(connectionString))
     {
         conn.Open();
         OleDbCommand cmd = new OleDbCommand();
         cmd.Connection = conn;
         OleDbTransaction tx = conn.BeginTransaction();
         cmd.Transaction = tx;
         try
         {
             for (int n = 0; n < SQLStringList.Count; n++)
             {
                 string strsql = SQLStringList[n].ToString();
                 if (strsql.Trim().Length > 1)
                 {
                     cmd.CommandText = strsql;
                     cmd.ExecuteNonQuery();
                 }
             }
             tx.Commit();
         }
         catch (System.Data.OleDb.OleDbException E)
         {
             tx.Rollback();
             throw new Exception(E.Message);
         }
     }
 }
Exemple #11
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // resolve the address to the Access database
            string fileNameString = this.MapPath(".");
            fileNameString += "..\\..\\..\\..\\data\\chartdata.mdb";

            // initialize a connection string
            string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

            // define the database query
            string mySelectQuery="SELECT GrossSales FROM SALES WHERE QuarterEnding < #01/01/2002#;";

            // create a database connection object using the connection string
            OleDbConnection myConnection = new OleDbConnection(myConnectionString);

            // create a database command on the connection using query
            OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

            // open the connection
            myCommand.Connection.Open();

            // create a database reader
            OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            // since the reader implements and IEnumerable, pass the reader directly into
            // the DataBind method with the name of the Column selected in the query
            Chart1.Series["Default"].Points.DataBindY(myReader, "GrossSales");

            // close the reader and the connection
            myReader.Close();
            myConnection.Close();
        }
        public void ReadExcelSheet(string fileName, string sheetName, Action<DataTableReader> actionForEachRow)
        {
            var connectionString = string.Format(ExcelSettings.Default.ExcelConnectionString, fileName);

            using (var excelConnection = new OleDbConnection(connectionString))
            {
                excelConnection.Open();

                if (sheetName == null)
                {
                    var excelSchema = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                    if (excelSchema != null)
                    {
                        sheetName = excelSchema.Rows[0]["TABLE_NAME"].ToString();
                    }
                }

                var excelDbCommand = new OleDbCommand(@"SELECT * FROM [" + sheetName + "]", excelConnection);

                using (var oleDbDataAdapter = new OleDbDataAdapter(excelDbCommand))
                {
                    var dataSet = new DataSet();
                    oleDbDataAdapter.Fill(dataSet);

                    using (var reader = dataSet.CreateDataReader())
                    {
                        while (reader.Read())
                        {
                            actionForEachRow(reader);
                        }
                    }
                }
            }
        }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int lgflg = 0;

        OleDbConnection conn = new OleDbConnection(ConfigurationSettings.AppSettings["classDB"]);
        OleDbCommand cmd = new OleDbCommand("SELECT * FROM student WHERE studentpassword = '" + password.Text + "' AND email = '" + userName.Text + "'", conn);

        conn.Open();
        OleDbDataReader myReader = cmd.ExecuteReader();

        while (myReader.Read())
        {
            lgflg = 1;
            Session.Add("fname", myReader["Contact_name"]);
            Session.Add("address", myReader["address"]);
            Session.Add("city", myReader["city"]);
            Session.Add("state", myReader["state"]);
            Session.Add("zipcode", myReader["zipcode"]);
        }
        myReader.Close();
        conn.Close();

        if (lgflg == 1)
        {
            Response.Write(Session["fname"]);
        }
        else
        {
            error.Visible = true;
        }
    }
 public IDataReader ExecuteDataReader(string connectionString, string query)
 {
     _connection = new OleDbConnection(connectionString);
     _connection.Open();
     var command = new OleDbCommand(query, _connection);
     return command.ExecuteReader();
 }
Exemple #15
0
        private void Autocomplete()
        {
            try
            {
                con = new OleDbConnection(cs);
                con.Open();
                OleDbCommand cmd = new OleDbCommand("SELECT distinct ProductName FROM product", con);
                DataSet ds = new DataSet();
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                da.Fill(ds, "Product");
                AutoCompleteStringCollection col = new AutoCompleteStringCollection();
                int i = 0;
                for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                {
                    col.Add(ds.Tables[0].Rows[i]["productname"].ToString());

                }
                txtProductName.AutoCompleteSource = AutoCompleteSource.CustomSource;
                txtProductName.AutoCompleteCustomSource = col;
                txtProductName.AutoCompleteMode = AutoCompleteMode.Suggest;

                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void addToDatabase(string sql)
        {
            OleDbConnection db = null;

            try
            {
                db = new OleDbConnection();
                db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + mFileName;
                db.Open();

                OleDbCommand command = new OleDbCommand(sql, db);
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                showErrorMessage(ex.Message);
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }
        }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            OleDbConnectionStringBuilder sb = new OleDbConnectionStringBuilder();
            sb.Provider = "Microsoft.ACE.OLEDB.12.0";
            sb.DataSource = Server.MapPath("/vedb01/uploads/db1.accdb");
            OleDbConnection conn = new OleDbConnection(sb.ConnectionString);
            conn.Open();
            string updateQuery = "UPDATE Bag SET [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] WHERE BagID= @ID";
            OleDbCommand com = new OleDbCommand(updateQuery, conn);

            com.Parameters.AddWithValue("@ID", txtBagId.Text);
            com.Parameters.AddWithValue("@name", txtBagName.Text);
            com.Parameters.AddWithValue("@supplier", txtSupplier.Text);
            com.Parameters.AddWithValue("@color", txtColor.Text);
            com.Parameters.AddWithValue("@category", txtCategory.Text);
            com.Parameters.AddWithValue("@price", txtPrice.Text);
            com.Parameters.AddWithValue("@description", txtDescription.Text);
            

            com.ExecuteNonQuery();

            lblMessage.Text = "The bag No " + txtBagId.Text +" was updated successfully " + txtBagName.Text + " !";

            conn.Close();
        }
        catch (Exception ex)
        {
            Response.Write("Error: " + ex.ToString());
            lblMessage.Text = "Error !";
        }
    }
Exemple #18
0
 /// <summary>
 /// 执行查询语句,返回DataSet
 /// </summary>
 /// <param name="SQLString">查询语句</param>
 /// <returns>DataSet</returns>
 public override DataSet ExecuteDataSet(string SQLString, params IDataParameter[] cmdParms)
 {
     using (OleDbConnection connection = new OleDbConnection(connectionString))
     {
         OleDbCommand cmd = new OleDbCommand();
         PrepareCommand(cmd, connection, null, SQLString, cmdParms);
         using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
         {
             DataSet ds = new DataSet();
             try
             {
                 da.Fill(ds, "ds");
                 cmd.Parameters.Clear();
             }
             catch (OleDbException e)
             {
                 //LogManage.OutputErrLog(e, new Object[] { SQLString, cmdParms });
                 throw;
             }
             finally
             {
                 cmd.Dispose();
                 connection.Close();
             }
             return ds;
         }
     }
 }
Exemple #19
0
 private void btn_Browser_Click(object sender, EventArgs e)
 {
     OpenFileDialog P_open = new OpenFileDialog();//创建打开文件对话框对象
     P_open.Filter = "文本文件|*.txt|所有文件|*.*";//设置筛选字符串
     if (P_open.ShowDialog() == DialogResult.OK)
     {
         txt_Path.Text = P_open.FileName;//显示文件路径
         string conn = string.Format(//创建连接字符串
              @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=text",
              P_open.FileName.Substring(0,P_open.FileName.LastIndexOf(@"\")));
         OleDbConnection P_OleDbConnection = new OleDbConnection(conn);//创建连接对象
         try
         {
             P_OleDbConnection.Open();//打开连接
             OleDbCommand cmd = new OleDbCommand(//创建命令对象
                 string.Format("select * from {0}",
                 P_open.FileName.Substring(P_open.FileName.LastIndexOf(@"\"),
                 P_open.FileName.Length - P_open.FileName.LastIndexOf(@"\"))),
                 P_OleDbConnection);
             OleDbDataReader oda = cmd.ExecuteReader();//得到数据读取器对象
             while (oda.Read())
             {
                txt_Message.Text  += oda[0].ToString();//得到文本文件中的字符串
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);//弹出消息对话框
         }
         finally
         {
             P_OleDbConnection.Close();//关闭连接
         }
     }
 }
Exemple #20
0
        public MSAccessDataUtility()
        {
           
            command = new OleDbCommand();
            command.Connection = GetConnection();

        }
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection();
        Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("app_data/productsdb.mdb");
        Conn.Open();
        //Response.Write(Conn.State);

        System.Data.OleDb.OleDbCommand Comm = new System.Data.OleDb.OleDbCommand();
        System.Data.OleDb.OleDbDataReader dr;
        Comm.Connection = Conn;

        Comm.CommandText = "select productid, productname, productiondescription, price, qoh, imagelocation from products";

        if (Request.Params["categoryid"] != null && Request.Params["categoryid"].Length >0)
        {
            Comm.CommandText += " where categoryid = ?" ;
            Comm.Parameters.AddWithValue("anything", Request.Params["categoryid"].ToString());
        }

        dr = Comm.ExecuteReader();
        bool firstone = true;
        Response.Write("{\"product\":[");
        while (dr.Read())
        {
             if (!firstone)
            {
                Response.Write(",");
            }
            Response.Write(dr[0].ToString());

            firstone = false;

        }
        Response.Write("]}");
    }
Exemple #22
0
        public DataTable sepetcevir(string uyeID, string map)
        {

            OleDbConnection cnn = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + map);
            cnn.Open();
            OleDbCommand cmd = new OleDbCommand("select sepet from uyeler where uyeid=" + uyeID, cnn);
            OleDbDataReader rdr = cmd.ExecuteReader();
            rdr.Read();
            string[] urunler = rdr[0].ToString().Split(',');

            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[3] { new DataColumn("fid"), new DataColumn("aciklama"), new DataColumn("fiyat") });

            if (rdr[0].ToString() != "")
            {
                foreach (string item in urunler)
                {
                    cmd.Dispose();
                    string fid = item;

                    cmd = new OleDbCommand("select * from fotolar where fot_id=" + fid, cnn);
                    OleDbDataReader rdr2 = cmd.ExecuteReader();
                    rdr2.Read();
                    string ack = rdr2[5].ToString();
                    string fiyat = rdr2[6].ToString();

                    dt.Rows.Add(fid, ack, fiyat);
                }
            }

            cnn.Close();

            return dt;
        }
Exemple #23
0
        public DbSource()
        {
            OleDbCommand cmdMyQuery = new OleDbCommand("SELECT * FROM DictionaryDB");

            DataTable dTable = DbUtils.SQLSelect(cmdMyQuery);
            m_orders = dTable;
        }
Exemple #24
0
        public static int AffectData(string TSQL, IDbConnection myConn, IDbTransaction myTrans, List<IDbDataParameter> myParams)
        {
            bool mustClose = false;
            if (myConn == null)
            {
                mustClose = true;
                myConn = clsConn.getConnOLE();
            }
            if (myConn.State != ConnectionState.Open)
                myConn.Open();
            OleDbCommand myCMD = new OleDbCommand();
            //
            myCMD.Connection = myConn as OleDbConnection;
            if (myTrans != null)
                myCMD.Transaction = myTrans as OleDbTransaction;
            //
            myCMD.CommandType = CommandType.Text;
            myCMD.CommandText = TSQL;
            myCMD.CommandTimeout = 180000;//3 phut
            //
            if (myParams != null)
                AttachParameters(myCMD, myParams);

            int CMDResult = myCMD.ExecuteNonQuery();
            //
            if (mustClose) myConn.Close();
            return CMDResult;
        }
Exemple #25
0
        //Create an Excel file with 2 columns: name and score:
        //Write a program that reads your MS Excel file through
        //the OLE DB data provider and displays the name and score row by row.

        static void Main()
        {
            OleDbConnection dbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +
            @"Data Source=D:\Telerik\DataBases\HW\ADONET\06. ReadExcel\Table.xlsx;Extended Properties=""Excel 12.0 XML;HDR=Yes""");
            OleDbCommand myCommand = new OleDbCommand("select * from [Sheet1$]", dbConn);
            dbConn.Open();
            //First way
            //using (dbConn) - I think it is better to use dbConn in using clause, but for the demo issues i dont use using.
            //{
            OleDbDataReader reader = myCommand.ExecuteReader();

            while (reader.Read())
            {
                string name = (string)reader["Name"];
                double score = (double)reader["Score"];
                Console.WriteLine("{0} - score: {1}", name, score);
            }
            //}

            dbConn.Close();
            //Second way
            dbConn.Open();
            Console.WriteLine();
            Console.WriteLine("Second Way");
            Console.WriteLine("----------");
            DataTable dataSet = new DataTable();
            OleDbDataAdapter adapter = new OleDbDataAdapter("select * from [Sheet1$]", dbConn);
            adapter.Fill(dataSet);

            foreach (DataRow item in dataSet.Rows)
            {
                Console.WriteLine("{0}|{1}", item.ItemArray[0], item.ItemArray[1]);
            }
            dbConn.Close();
        }
Exemple #26
0
    public void binderStudentInfo(string username)
    {
        try
        {
            OleDbConnection con=DB.createcon();
            OleDbCommand cmd=new OleDbCommand();
            cmd.CommandText="select * from [student] where [studentUsername]='"+username+"'";
            cmd.Connection=con;
            con.Open();
            OleDbDataReader odr= cmd.ExecuteReader();
            while(odr.Read()){
               this.userName.Text=username;
                this.student_name.Value=odr["studentName"].ToString();
                //this.student_id.Value = odr["studentID"].ToString();
                //this.student_xibie.Value = odr["studentDepartment"].ToString();
               // this.student_grate.Value = odr["studentGrade"].ToString();
                //this.student_class.Value = odr["studentClass"].ToString();
                //this.tel.Value = odr["studentTel"].ToString();
                this.qq.Value = odr["studentQQ"].ToString();
                this.about.Value = odr["studentAbout"].ToString();

                ////this.ChTypeTrainCount.Text=odr["trainChCount"].ToString();
                //this.EnTypeTrainCount.Text=odr["trainEnCount"].ToString();
                //this.ChypeMatchCount.Text=odr["mathchChCount"].ToString();
                //this.EnTypeMatchCount.Text=odr["mathchEnCount"].ToString();
            }
            odr.Close();
            con.Close();
        }
        catch (Exception exp)
        {
            saveErrorMessage.writeFile("查询学生的个人信息时出错",exp.ToString());
        }
    }
Exemple #27
0
    public void updateProductPrice(ProductInBag Product)
    {
        OleDbConnection myConn = new OleDbConnection(Connstring.getConnectionString());
        OleDbCommand myCmd;
        OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();
        try
        {
            myCmd = new OleDbCommand("UpdateUnitPrice", myConn);
            myCmd.CommandType = CommandType.StoredProcedure;
            OleDbParameter objParam;

            objParam = myCmd.Parameters.Add("@UnitPrice", OleDbType.Decimal);
            objParam.Direction = ParameterDirection.Input;
            objParam.Value = Product.Price;

            objParam = myCmd.Parameters.Add("@ProductID", OleDbType.Integer);
            objParam.Direction = ParameterDirection.Input;
            objParam.Value = Product.ProdID;

            myConn.Open();
            myCmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            myConn.Close();
        }
    }
        //Gets the value of the show id. 
        public int getShowID(OleDbCommand command)
        {
            int showID = 0;
            try
            {
                getSetCon().Open(); //Open con
                using (OleDbDataReader reader = command.ExecuteReader()) 
                {
                    //Reads all values.
                    while (reader.Read())
                    {
                        showID = Convert.ToInt32(reader["Show_ID"].ToString()); //Get the ID
                    }
                }
            }
            
            catch(Exception ex)
            {
                //Error message
                MetroMessageBox.Show(form, ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                //Clean up
                command.Dispose();
                con.Close();
            }
            //Return the ID
            return showID;

        }
Exemple #29
0
        public override List<DomainAlias> GetDomainAliases(string domainName)
        {
            var _tmp = new List<DomainAlias>();

            using (OleDbConnection _conn = new OleDbConnection(Settings.Default.connectionString))
            {
                _conn.Open();
                using (OleDbCommand _cmd = new OleDbCommand(@"SELECT domain_aliases.name AS alias, domains.name AS [domain], domain_aliases.status
                                                                FROM (domain_aliases INNER JOIN
                                                            domains ON domain_aliases.dom_id = domains.id)
                                                                WHERE (domain_aliases.status = 0) AND (domains.name = ?)", _conn))
                {
                    _cmd.CommandType = CommandType.Text;
                    _cmd.Parameters.AddWithValue("NAME", domainName);

                    using (OleDbDataReader _read = _cmd.ExecuteReader())
                    {
                        while (_read.Read())
                        {
                            var _d = new DomainAlias();
                            _d.Domain = _read["domain"].ToString();
                            _d.Alias = _read["alias"].ToString();

                            _tmp.Add(_d);
                        }
                    }
                }
                _conn.Close();
            }

            return _tmp;
        }
        public static void readFromDB(OleDbConnection conn)
        {
            string testSelect = " SELECT * FROM ImportAccess";
            OleDbCommand comm = new OleDbCommand(testSelect, conn);
            OleDbDataReader dr = comm.ExecuteReader();
            object[] buffer = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            StringBuilder sb = new StringBuilder();
            while (dr.Read())// populate buffer with values from db
            {
                int value = dr.GetValues(buffer);

                for (int i = 0; i < buffer.Length; i++)
                {
                    sb.Append(buffer[i] + ",");
                }
                sb.Remove(buffer.Length - 1, 1);
            }
            ConsoleKeyInfo cki = new ConsoleKeyInfo();
            while (true)    // keep console window open
            {
                Console.WriteLine("Returned values " + sb.ToString());
                cki = Console.ReadKey(true);
                if (cki.Key == ConsoleKey.X)
                {
                    break;
                }
            }
            dr.Close();
        }