当前位置: 首页>>代码示例>>C#>>正文


C# System.Data.OleDb.OleDbCommand.ExecuteNonQuery方法代码示例

本文整理汇总了C#中System.Data.OleDb.OleDbCommand.ExecuteNonQuery方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.OleDb.OleDbCommand.ExecuteNonQuery方法的具体用法?C# System.Data.OleDb.OleDbCommand.ExecuteNonQuery怎么用?C# System.Data.OleDb.OleDbCommand.ExecuteNonQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.OleDb.OleDbCommand的用法示例。


在下文中一共展示了System.Data.OleDb.OleDbCommand.ExecuteNonQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddEvent

        public int AddEvent(String eventName, String eventRoom,
			String eventAttendees, String eventDate)
        {
            System.Data.OleDb.OleDbConnection oleDbConnection1;
            System.Data.OleDb.OleDbDataAdapter daEvents;
            DataSet ds;

            oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
            oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\\Inetpub\\wwwroot\\PCSWebApp3\\PCSWebApp3.mdb";
            String oleDbCommand = "INSERT INTO Events (Name, Room, AttendeeList," +
                " EventDate) VALUES ('" + eventName + "', '" +
                eventRoom + "', '" + eventAttendees + "', '" +
                eventDate + "')";
            System.Data.OleDb.OleDbCommand insertCommand =
                new System.Data.OleDb.OleDbCommand(oleDbCommand,
                oleDbConnection1);
            oleDbConnection1.Open();

            int queryResult = insertCommand.ExecuteNonQuery();
            if (queryResult == 1)
            {
                daEvents = new System.Data.OleDb.OleDbDataAdapter(
                    "SELECT * FROM Events", oleDbConnection1);
                ds = (DataSet)Application["ds"];
                ds.Tables["Events"].Clear();
                daEvents.Fill(ds, "Events");
                Application.Lock();
                Application["ds"] = ds;
                Application.UnLock();
                oleDbConnection1.Close();
            }
            return queryResult;
        }
开发者ID:alannet,项目名称:example,代码行数:33,代码来源:Service1.asmx.cs

示例2: buttonInfoMessage_Click

        private void buttonInfoMessage_Click(object sender, EventArgs e)
        {

            /**** Create this Store Procedure in the tempdb database first ****
                        Create Proc TestInfoMessage
                        as
                        Print 'Using a Print Statement'
                        RaisError('RaisError in Stored Procedures', 9, 1)
            ****************************************************/

            //1. Make a Connection
            System.Data.OleDb.OleDbConnection objOleCon = new System.Data.OleDb.OleDbConnection();
            objOleCon.ConnectionString = strConnection;
            objOleCon.Open();

            objOleCon.InfoMessage += new System.Data.OleDb.OleDbInfoMessageEventHandler(objOleCon_InfoMessage);

            //2. Issue a Command
            System.Data.OleDb.OleDbCommand objCmd;
            objCmd = new System.Data.OleDb.OleDbCommand("Raiserror('Typical Message Goes Here', 9, 1)", objOleCon);
            objCmd.ExecuteNonQuery();
            objCmd = new System.Data.OleDb.OleDbCommand("Exec TestInfoMessage", objOleCon); //This executes the stored procedure.
            objCmd.ExecuteNonQuery();

            //3. Process the Results
            /** No Results at this time **/

            //4. Clean up code
            objOleCon.Close();
        }
开发者ID:lorneroy,项目名称:CSharpClass,代码行数:30,代码来源:Form1.cs

示例3: insertImage

 public void insertImage(string wkImg)
 {
     System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand();
     cmd.CommandText = "Insert into [" + TableName + "] (imageName) values('" + wkImg + "')  ";
        cmd.Connection = conn;
         cmd.ExecuteNonQuery();
 }
开发者ID:ashishjain76,项目名称:AutoConvertor,代码行数:7,代码来源:DataBase.cs

示例4: btnInsert_Click

        protected void btnInsert_Click(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/products.mdb");
            Conn.Open();
            //Response.Write(Conn.State);

            string strSQL = "insert into [users] ([username], firstname, lastname, email, [password]) values (?,?,?,?,?)";
            object returnVal;

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

            Comm.CommandText = "select [username] from [users] where [username] = ?";
            Comm.Parameters.AddWithValue("[username]", txtUserName.Text);
            returnVal = Comm.ExecuteScalar();
            if (returnVal == null)
            {
                Comm.Parameters.Clear();
                Comm.CommandText = strSQL;
                Comm.Parameters.AddWithValue("username", txtUserName.Text);
                Comm.Parameters.AddWithValue("firstname", txtFName.Text);
                Comm.Parameters.AddWithValue("lastname", txtLName.Text);
                Comm.Parameters.AddWithValue("email", txtEmail.Text);
                Comm.Parameters.AddWithValue("password", txtPassword.Text);
                Comm.ExecuteNonQuery();
            }
            else {
                Response.Write("Username already exists.");
            }
            Conn.Close();
            Conn = null;
        }
开发者ID:jasonhuber,项目名称:2010FallB_CIS407,代码行数:33,代码来源:InsertPerson.aspx.cs

示例5: btnGo_Click

        protected void btnGo_Click(object sender, EventArgs e)
        {
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            string sql = "";
            System.Data.DataSet ds = new System.Data.DataSet();
            System.Data.OleDb.OleDbDataReader dr;
            System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand();
            //http://www.c-sharpcorner.com/UploadFile/dchoksi/transaction02132007020042AM/transaction.aspx
            //get this from connectionstrings.com/access
            conn.ConnectionString = txtConnString.Text;
            conn.Open();
            //here I can talk to my db...
            System.Data.OleDb.OleDbTransaction Trans;
            Trans = conn.BeginTransaction(System.Data.IsolationLevel.Chaos);

            try
            {

                comm.Connection = conn;
                comm.Transaction = Trans;
               // Trans.Begin();

                //Console.WriteLine(conn.State);
                sql = txtSQL.Text;
                comm.CommandText = sql;
                if (sql.ToLower().IndexOf("select") == 0)
                {
                    dr = comm.ExecuteReader();
                    while (dr.Read())
                    {
                        txtresults.Text = dr.GetValue(0).ToString();
                    }
                }
                else
                {
                    txtresults.Text = comm.ExecuteNonQuery().ToString();
                }
                Trans.Commit();
            }
            catch (Exception ex)
            {
                txtresults.Text = ex.Message;
                Trans.Rollback();
            }
            finally
            {

                comm.Dispose();
                conn.Close();
                conn = null;
            }
        }
开发者ID:jasonhuber,项目名称:2010Fall_CIS407,代码行数:52,代码来源:Default.aspx.cs

示例6: btnGo_Click

        private void btnGo_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            //open connection to database

            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            conn.ConnectionString = txtConnString.Text;
            conn.Open();
            // MessageBox.Show(conn.State.ToString());
            //create my command
            System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand();
            comm.Connection = conn;
            //send the sql through the command
            comm.CommandText = txtSQL.Text;

            //receive the result into a data container.

            System.Data.OleDb.OleDbDataReader dr;
            try
            {

                if (txtSQL.Text.ToUpper().StartsWith("SELECT"))
                {
                    dr = comm.ExecuteReader();
                    System.Data.DataTable dt = new DataTable();
                    dt.Load(dr);
                    Grid1.AutoGenerateColumns = true;
                    //bind the result to the grid

                    Grid1.DataSource = dt;
                }
                else
                {
                    MessageBox.Show(comm.ExecuteNonQuery().ToString());
                }

            }
            catch (Exception ex)
            {

                lblError.Text = ex.Message;
            }
            finally
            {
                conn.Close();

            }
        }
开发者ID:jasonhuber,项目名称:CIS336-Fall-B,代码行数:48,代码来源:Form1.cs

示例7: Main

        static void Main(string[] args)
        {
            string connstring =
            @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\DropBox\My Dropbox\Devry\CIS407\SU10B\day5\NorthWind.mdb;";
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            string sql = "";
            System.Data.DataSet ds = new System.Data.DataSet();
            System.Data.OleDb.OleDbDataReader dr;
            System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand();

            try
            {
                //get this from connectionstrings.com/access
                conn.ConnectionString = connstring;
                conn.Open();
                //here I can talk to my db...
                comm.Connection = conn;

                //Console.WriteLine(conn.State);
                sql = Console.ReadLine();
                comm.CommandText = sql;
                if (sql.ToLower().IndexOf("select") == 0)
                {
                    dr = comm.ExecuteReader();
                    while (dr.Read())
                    {
                        Console.WriteLine(dr.GetString(0));
                    }
                }
                else
                {
                    Console.WriteLine(comm.ExecuteNonQuery().ToString());
                }
            }
            catch ( Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.Read();
            }
            finally
            {
                Console.ReadLine();
                comm.Dispose();
                conn.Close();
                conn = null;
            }
        }
开发者ID:jasonhuber,项目名称:2010Fall_CIS407,代码行数:47,代码来源:Program.cs

示例8: btnGo_Click

        protected void btnGo_Click(object sender, EventArgs e)
        {
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            string sql = "";
            System.Data.DataSet ds = new System.Data.DataSet();
            System.Data.OleDb.OleDbDataReader dr;
            System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand();

            try
            {
                //get this from connectionstrings.com/access
                conn.ConnectionString = txtConnString.Text;
                conn.Open();
                //here I can talk to my db...
                comm.Connection = conn;

                //Console.WriteLine(conn.State);
                sql = txtSQL.Text;
                comm.CommandText = sql;
                if (sql.ToLower().IndexOf("select") == 0)
                {
                    dr = comm.ExecuteReader();
                    while (dr.Read())
                    {
                        txtresults.Text = dr.GetValue(0).ToString();
                    }
                }
                else
                {
                    txtresults.Text = comm.ExecuteNonQuery().ToString();
                }
            }
            catch (Exception ex)
            {
                txtresults.Text = ex.Message;

            }
            finally
            {

                comm.Dispose();
                conn.Close();
                conn = null;
            }
        }
开发者ID:jasonhuber,项目名称:2010Fall_CIS407,代码行数:45,代码来源:Default.aspx.cs

示例9: Querry

 public void Querry(string Que, string DataBasePath)
 {
     string conn = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataBasePath;
     System.Data.OleDb.OleDbConnection connect = new System.Data.OleDb.OleDbConnection(conn);
     connect.Open();
     using (System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand(Que, connect))
     {
         try
         {
             command.ExecuteNonQuery();
         }
         catch (System.Data.OleDb.OleDbException ex)
         {
             MessageBox.Show("Произошла ошибка при создании таблицы\n" + ex.Message);
         }
     }
     connect.Close();
 }
开发者ID:yshtepo,项目名称:extowd,代码行数:18,代码来源:DataCollect.cs

示例10: SaveAs

 public bool SaveAs(string fileName, System.Data.DataTable dataTable)
 {
     if (dataTable == null || dataTable.Rows.Count == 0) return false;
     if (xlApp == null) return false;
     _workbook = xlApp.Workbooks.Add(Type.Missing);
     _worksheet = (Worksheet)_workbook.Worksheets[1];
     for (var i = 0; i < dataTable.Columns.Count; i++)
     {
         _worksheet.Cells[1, i + 1] = dataTable.Columns[i].ColumnName;
         //range = (Range)worksheet.Cells[1, i + 1];
         //range.Interior.ColorIndex = 15;
         //range.Font.Bold = true;
     }
     _workbook.SaveAs(fileName,XlFileFormat.xlWorkbookNormal, "", "", false, false, XlSaveAsAccessMode.xlExclusive,XlPlatform.xlWindows, false, false, false, false);
     _workbook.Close(true, fileName, false);
     xlApp.Quit();
     _connectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + fileName + "';Extended Properties=Excel 8.0;"; // строка подключения
     using (var excelConn = new System.Data.OleDb.OleDbConnection(_connectionString)) // используем OleDb
     {
         var queryValues = String.Empty;
         excelConn.Open();
         for (var i = 0; i < dataTable.Rows.Count; i++)
         {
             for (var c = 0; c < dataTable.Columns.Count; c++)
             {
                 queryValues += dataTable.Rows[i][c] + "','";
             }
             queryValues = queryValues.Substring(0, queryValues.Length - 3);
             var writeCmd = new System.Data.OleDb.OleDbCommand("INSERT INTO [Лист1$] VALUES ('" + queryValues + "')", excelConn);
             writeCmd.ExecuteNonQuery(); // вставляем данные в лист1 файла - filename
             writeCmd.Dispose();
             queryValues = String.Empty;
         }
         excelConn.Close();
     }
     return System.IO.File.Exists(fileName);
 }
开发者ID:pulse-computer-consulting,项目名称:NucleusPub,代码行数:37,代码来源:Excel.cs

示例11: cmdSubmit_Click

        protected void cmdSubmit_Click(object sender, EventArgs e)
        {
            string connstring =
              @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\DropBox\My Dropbox\Devry\CIS407\SU10B\day7\dbreader\dbreader\App_Data\Shoes.mdb;";
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            string sql = "";
            System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand();
            conn.ConnectionString = connstring;
            conn.Open();
            comm.Connection = conn;

            //Console.WriteLine(conn.State);
            sql = "Insert into customers (customerid, fname, lname, [password], email)";
            sql += " values  (?, ?, ?, ?, ?)";
            //http://www.4guysfromrolla.com/webtech/092601-1.2.shtml
            comm.CommandText = sql;
            comm.Parameters.AddWithValue("customerid", txtID.Text);
            comm.Parameters.AddWithValue("fname", txtFName.Text);
            comm.Parameters.AddWithValue("lname", txtLName.Text);
            comm.Parameters.AddWithValue("passwd", txtPassWD.Text);
            comm.Parameters.AddWithValue("email", txtEmail.Text);

            comm.ExecuteNonQuery();
        }
开发者ID:jasonhuber,项目名称:2010Fall_CIS407,代码行数:24,代码来源:Insert.aspx.cs

示例12: create_datasetfile


//.........这里部分代码省略.........
        //                    " WHERE           (dbo.device.type = '" + com_monitor_type.Text + "')";
        //    }
        //    else if ((Rb_Gateway.Checked) && (Rb_DeviceType.Checked) && (Ch_additionalSensors.Checked))
        //    {
        //        condition = " SELECT DISTINCT device_1.id, device_1.title, device_1.root_id, device_1.gateway_id, dbo.device.type" +
        //                    " FROM            dbo.device INNER JOIN" +
        //                    "                          dbo.Dependencies ON dbo.device.id = dbo.Dependencies.device INNER JOIN" +
        //                    "                          dbo.device AS device_1 ON dbo.Dependencies.dependon_device = device_1.id" +
        //                    " WHERE        (dbo.device.gateway_id = "+int.Parse(com_gateway.SelectedValue.ToString())+") AND (dbo.device.type = '"+com_monitor_type.Text+"')";

        //    }
        //    if ((Rb_DeviceType.Checked) && (Ch_additionalSensors.Checked))
        //    {
        //        cmd = new SqlCommand(condition, con2db);
        //        adaptor = new SqlDataAdapter(cmd);
        //        DTt = new DataSet();
        //        adaptor.Fill(DTt);
        //        drgoods = DTt.Tables[0].Rows;
        //        count_headers+=DTt.Tables[0].Rows.Count;
        //       // lab_headers.Text = "=" + count_headers;

        //        foreach (DataRow dtdep in drgoods)
        //        {
        //            string s = dtdep[1].ToString() + "(" + dtdep[0].ToString() + "/" + dtdep[2].ToString() + ":" + dtdep[3].ToString() + ")";
        //            Lb_Headers.Items.Add(s);
        //        }
        //    }
        //    con2db.Close();
        //    if (Lb_Headers.Items.Count == 1)
        //        Lb_Headers.Items.Clear();
        //    else
        //        lab_headers.Text = "=" + (++count_headers);
        //}
        #endregion
        ///-------------------------------------------------
        private void create_datasetfile()
        {
            System.Data.OleDb.OleDbConnection MyConnection;
         
            string s=""; 
            string t = "_"+DateTime.Now.Year+"-"+DateTime.Now.Month+"-"+DateTime.Now.Day+"-h" + DateTime.Now.ToLocalTime().Hour.ToString();
            txt_FileName.Text = G_Variables.Log_Title + t;
            s = G_Variables.Log_Path + "\\" + G_Variables.Log_Title + t;
            bool continue_work = true; bool append = false;
            if(File.Exists(s + ".XLS") == true)
            {
                DialogResult dr = MessageBox.Show(" File was Exist at that path with the same title, because another file was created within the same hour with the same criteria \n Do you want to continue process replacing existing file with that new file ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dr == DialogResult.Yes)
                { File.Delete(s + ".XLS"); continue_work = true; }
                else
                {
                    dr = MessageBox.Show(" Do You want to continue using the same file to append data on it?", "info.", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.No)
                    {
                        dr = MessageBox.Show(" Do You want to continue using an alternative title which will be (prev. titel plus minutes)?", "info.", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        if (dr == DialogResult.OK)
                        {
                            s += "-m" + DateTime.Now.ToLocalTime().Minute.ToString();
                            txt_FileName.Text = G_Variables.Log_Title + t + "-m" + DateTime.Now.ToLocalTime().Minute.ToString(); ;
                            continue_work = true;
                        }
                        else
                            continue_work = false;
                    }
                    else append = true;
                    
                }
            }
            if(continue_work) 
            {
                try
                {
                    columns = Lb_Headers.Items.Count;
                    if (Lb_Rules.Items[1].ToString().Contains('#'))
                        Cur_Type = "Network";
                    else
                        Cur_Type = "Gateway";
                    Cur_Ds_File = s;
                    Cur_File_Sheet = G_Variables.Log_Title;
                    string header = "";
                    MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + Cur_Ds_File + "';Extended Properties='Excel 8.0;HDR=Yes'");
                    MyConnection.Open();
                    if( Lb_Headers.Items.Count>0)
                        header += "[" + Lb_Headers.Items[0] + "] datetime,";
                    for (int i = 1; i < Lb_Headers.Items.Count - 1; i++)
                        header += "[" + Lb_Headers.Items[i] + "] int,";
                    header += "[" + Lb_Headers.Items[Lb_Headers.Items.Count - 1] + "] int";
                    if (!append)
                    {
                        System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("create table [" + Cur_File_Sheet + "] (" + header + " ) ", MyConnection);
                        cmd.ExecuteNonQuery();
                    }
                    MyConnection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
开发者ID:MinaYounan-CS,项目名称:WoT-Testbed-Environment,代码行数:101,代码来源:Form1.cs

示例13: AddToList

        private void AddToList(string msg)
        {
            int n;
            DateTime st = System.DateTime.Now;
            if (Bt_Record.Text == "Stop Rec.")
            {
                DGV_Statistics[3, 0].Value = (st.Ticks - LastReceiveTime.Ticks) / 1000000.0;   // DGV_Statistics[3,0].Value = st.Subtract(LastReceiveTime);
                if (int.Parse(txt_time.Text) <= 0) txt_time.Text = "1000";
                textBox1.Text =Math.Truncate((((st.Ticks - LastReceiveTime.Ticks) / 10000.0) - double.Parse(txt_time.Text))).ToString();
                textBox2.Text =Math.Truncate((double.Parse(textBox2.Text) + double.Parse(textBox1.Text))).ToString();
            }
            LastReceiveTime = st; //last receive time

            if (msg.IndexOf("GW_ID=")>-1) // discovering gateways
            { 
               int ind = msg.IndexOf("=");
               int indx = (msg.IndexOf("\r")-ind-1);
                
               cur_GW_ID += msg.Substring(ind+1,indx);
               bool add_gw = false;
               int y=int.Parse(msg.Substring(ind+1)); 
               foreach(int i in G_Variables.Gateways_ID)
                   if (y == G_Variables.Gateways_ID[i]) add_gw = true;
               if (!add_gw) //if it is new one so it will be added
               { G_Variables.Gateways_ID[G_Variables.No_GWs_Availble++] = int.Parse(msg.Substring(ind + 1)); txt_time.Text = (1000 * G_Variables.No_GWs_Availble)+""; }
               for (int i = 0; i < (DGV_Gateways_Available.Rows.Count - 1); i++)
                   if (int.Parse(DGV_Gateways_Available.Rows[i].Cells[0].Value.ToString()) == y)
                       DGV_Gateways_Available.Rows[i].Cells[4].Value = Properties.Resources.on;
               
            }
            else if((msg.Contains("Connected"))||(msg.Contains("Disconnected")))
            {
                n = msg_listbox.Items.Add(msg);
                msg_listbox.SelectedIndex = n;
                msg_listbox.ClearSelected();
            }
            else
            {
                System.Data.OleDb.OleDbConnection MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + Cur_Ds_File + "';Extended Properties='Excel 8.0;HDR=Yes'");
                n = Lb_Sensors_Data.Items.Add(msg);
                Lb_Sensors_Data.SelectedIndex = n;  Lb_Sensors_Data.ClearSelected();

                if (Bt_Record.Text == "Stop Rec.")
                {
                    count_sensor_records++;
                    DGV_Statistics[0, 0].Value = count_sensor_records + ""; lab_SensorRecords.Text = "Recieved =" + count_sensor_records + " msg.(s)";
                }
                DateTime d = new DateTime();
                d = DateTime.Parse(DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute);
                
                if ((start_record) && (msg.Contains("@")))// && (rec_state != "Network"))
                {
                    bool missing_headers_order = false;
                    try
                    {
                        int ind_under = (msg.IndexOf('_') - 1);
                        string eds = msg.Substring(2, ind_under - 1);
                        int gw = int.Parse(eds);

                        string s = msg.Substring(msg.LastIndexOf(":") + 1);
                        int x = s.LastIndexOf(',');
                        s = s.Substring(0, s.Length - 2);

                        s = s.Replace("@", "");
                        string gw_headers = "";

                        for (int i = 0; i < G_Variables.No_GWs_Availble; i++)
                            if (G_Variables.Gateways_ID[i] == gw)
                            {
                                if (Cur_Type == "Network")
                                    gw_headers = headers[i];
                                else
                                    gw_headers = headers[0];
                            }
                        x = gw_headers.LastIndexOf(',');
                        gw_headers = gw_headers.Substring(0, gw_headers.Length - 1);
                        var hlist = gw_headers.Split(',');
                        var vlist = s.Split(',');
                        // MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + Cur_Ds_File + "';Extended Properties='Excel 8.0;HDR=Yes'");
                        MyConnection.Open();
                        System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand();

                        // to update
                        string sets = ""; string sql = "";
                        int NumOfUpdates = 0;
                        if ((Cur_Type == "Network") && (G_Variables.No_GWs_Availble > 1))
                        {
                            for (int i = 0; i < hlist.Length - 1; i++)
                            {
                                try { sets += "[" + hlist[i] + "]=" + vlist[i] + ","; }
                                catch { missing_headers_order = true; }
                            }
                            sets += "[" + hlist[hlist.Length - 1] + "]=" + vlist[vlist.Length - 1];

                            sql = " update [" + Cur_File_Sheet + "] set " + sets + " where [RecDateTime] like '" + d + "' ";
                            cmd.CommandText = sql;
                            cmd.Connection = MyConnection;
                            NumOfUpdates = cmd.ExecuteNonQuery();
                        }
                        if (NumOfUpdates == 0)
//.........这里部分代码省略.........
开发者ID:MinaYounan-CS,项目名称:WoT-Testbed-Environment,代码行数:101,代码来源:Form1.cs

示例14: insert_data_to_Excel

        public static bool insert_data_to_Excel(List<TaiSanHienThi> list, String file_path)
        {
            try
            {
                const String ID = "A";
                const String NGAY_CT = "B";
                const String SOHIEU_CT = "C";
                const String TEN = "D";
                const String LOAI = "E";
                const String DONVITINH = "F";
                const String NGAY_SD = "G";
                const String NUOC_SX = "H";
                const String SOLUONG = "I";
                const String DONGIA = "J";
                const String THANHTIEN = "K";
                const String TINHTRANG = "L";
                const String VITRI = "O";
                const String PHONG = "N";
                const String DONVI_QL = "M";
                const String GHICHU = "P";

                String currentPath = Directory.GetCurrentDirectory();
                String path = Path.Combine(currentPath, "Excel");
                //String path = "F:";
                String file = "";
                String fileName = "MauExport.xls";
                if (Directory.Exists(path))
                {
                    file = path + "//" + fileName;
                    if (System.IO.File.Exists(file))
                    {
                        File.Delete(file_path);
                        File.Copy(file, file_path);
                        System.Data.OleDb.OleDbConnection MyConnection;

                        MyConnection = new System.Data.OleDb.OleDbConnection(String.Format("provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';Extended Properties=Excel 8.0;", file_path));
                        MyConnection.Open();
                        int i = 0;
                        foreach (TaiSanHienThi ts in list)
                        {
                            i++;
                            if (i % 100 == 0)
                            {
                                MyConnection.Close();
                                MyConnection = new System.Data.OleDb.OleDbConnection(String.Format("provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';Extended Properties=Excel 8.0;", file_path));
                                MyConnection.Open();
                            }
                            System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
                            string sql = null;
                            myCommand.Connection = MyConnection;
                            sql = String.Format("Insert into [TaiSan$A2:P9999] ({0}) values(@id, @ngay_ct, @sohieu_ct, @ten, @loai, @donvitinh, @ngay_sd, @nuoc_sx, @soluong, @dongia, @thanhtien, @tinhtrang, @vitri, @phong, @donvi_ql, @ghichu)",
                                ID + "," + NGAY_CT + "," + SOHIEU_CT + "," + TEN + "," + LOAI + "," + DONVITINH + "," + NGAY_SD + "," + NUOC_SX + "," + SOLUONG + "," + DONGIA + "," + THANHTIEN + "," + TINHTRANG + "," + VITRI + "," + PHONG + "," + DONVI_QL + "," + GHICHU);
                            myCommand.CommandText = sql;
                            myCommand.Parameters.AddWithValue("@id", ts.id);
                            myCommand.Parameters.AddWithValue("@ngay_ct", ts.ngay_ct != null ? (Object)((DateTime)ts.ngay_ct).ToShortDateString() : DBNull.Value);
                            myCommand.Parameters.AddWithValue("@sohieu_ct", (Object)ts.sohieu_ct ?? DBNull.Value);
                            myCommand.Parameters.AddWithValue("@ten", ts.ten);
                            myCommand.Parameters.AddWithValue("@loai", ts.loaits);
                            myCommand.Parameters.AddWithValue("@donvitinh", ts.donvitinh);
                            myCommand.Parameters.AddWithValue("@ngay_sd", ts.ngay != null ? (Object)((DateTime)ts.ngay).ToShortDateString() : DBNull.Value);
                            myCommand.Parameters.AddWithValue("@nuoc_sx", (Object)ts.nuocsx ?? DBNull.Value);
                            myCommand.Parameters.AddWithValue("@soluong", ts.soluong);
                            myCommand.Parameters.AddWithValue("@dongia", ts.dongia);
                            myCommand.Parameters.AddWithValue("@thanhtien", ts.thanhtien);
                            myCommand.Parameters.AddWithValue("@tinhtrang", ts.tinhtrang);
                            myCommand.Parameters.AddWithValue("@vitri", (Object)ts.vitri ?? DBNull.Value);
                            myCommand.Parameters.AddWithValue("@phong", (Object)ts.phong ?? DBNull.Value);
                            myCommand.Parameters.AddWithValue("@donvi_ql", (Object)ts.dvquanly ?? DBNull.Value);
                            myCommand.Parameters.AddWithValue("@ghichu", (Object)ts.ghichu ?? DBNull.Value);
                            myCommand.ExecuteNonQuery();
                            if (i % 500 == 0)
                            {

                            }
                        }
                        MyConnection.Close();
                        return true;
                    }
                    else
                        return false;
                }
                else
                    return false;
            }
            catch(Exception ex)
            {
                Debug.WriteLine("ExcelDataBaseHelper->insert_data_to_Excel: " + ex.Message);
                return false;
            }
        }
开发者ID:quocdunginfo,项目名称:QuanLyTaiSan,代码行数:90,代码来源:ExcelDataBaseHelper.cs

示例15: WriteNSX

 private static void WriteNSX(String fileName, String sheet, String stt, String text)
 {
     try
     {
         if (!stt.Equals(""))
         {
             //Ghi file Excel
             using (System.Data.OleDb.OleDbConnection MyConnection = new System.Data.OleDb.OleDbConnection(GetConnectionString(fileName)))
             {
                 System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
                 string sql = null;
                 MyConnection.Open();
                 myCommand.Connection = MyConnection;
                 sql = String.Format("Update [{0}$] set NSX = @nsx where STT = @stt", sheet);
                 myCommand.CommandText = sql;
                 myCommand.Parameters.AddWithValue("@nsx", text);
                 myCommand.Parameters.AddWithValue("@stt", stt);
                 myCommand.ExecuteNonQuery();
                 MyConnection.Close();
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("ExcelDataBaseHelper->WriteFileWithRange: " + ex.Message);
     }
 }
开发者ID:quocdunginfo,项目名称:QuanLyTaiSan,代码行数:27,代码来源:ExcelDataBaseHelper.cs


注:本文中的System.Data.OleDb.OleDbCommand.ExecuteNonQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。