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


C# OleDbConnection.Open方法代码示例

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


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

示例1: SaveRecord

        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;
        }
开发者ID:FuriousLogic,项目名称:LA3_DataTransfer,代码行数:28,代码来源:CoreFunctions.cs

示例2: LinkButton5_Click

 protected void LinkButton5_Click(object sender, EventArgs e)
 {
     OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(@"App_Data\db.mdb")+";Persist Security Info=True");
     OleDbCommand cmd = new OleDbCommand("insert into siparis (UYEID,ADRES,TEL,DURUMU) values (@UYEID,@ADRES,@TEL,@DURUMU)",baglanti);
     cmd.Parameters.AddWithValue("@UYEID",((DataTable)(Session["UYE"])).Rows[0][0].ToString());
      cmd.Parameters.AddWithValue("@ADRES",TextBox1.Text);
      cmd.Parameters.AddWithValue("@TEL",TextBox2.Text);
      cmd.Parameters.AddWithValue("@DURUMU","Beklemede");
      baglanti.Open();
      cmd.ExecuteNonQuery();
      baglanti.Close();
      OleDbDataAdapter da = new OleDbDataAdapter("select ID from siparis where [email protected] order by ID DESC",baglanti);
      da.SelectCommand.Parameters.AddWithValue("@UYEID",((DataTable)(Session["UYE"])).Rows[0][0].ToString());
      DataTable dt = new DataTable();
      da.Fill(dt);
     DataTable sdt=((DataTable)(Session["SEPET"]));
     for (int i = 0; i < sdt.Rows.Count; i++)
         {
             OleDbCommand scmd = new OleDbCommand("insert into sepet (SIPID,URUNID,URUN,FIYAT,ADET,TOPLAM) VALUES (@SIPID,@URUNID,@URUN,@FIYAT,@ADET,@TOPLAM)",baglanti);
             scmd.Parameters.Clear();
             scmd.Parameters.AddWithValue("@SIPID",dt.Rows[0][0].ToString());
         scmd.Parameters.AddWithValue("@URUNID",sdt.Rows[i]["ID"].ToString());
         scmd.Parameters.AddWithValue("@URUN",sdt.Rows[i]["URUN"].ToString());
         scmd.Parameters.AddWithValue("@FIYAT",sdt.Rows[i]["FIYAT"].ToString());
         scmd.Parameters.AddWithValue("@ADET",sdt.Rows[i]["ADET"].ToString());
         scmd.Parameters.AddWithValue("@TOPLAM", sdt.Rows[i]["TOPLAM"].ToString());
         baglanti.Open();
         scmd.ExecuteNonQuery();
         baglanti.Close();
         }
     Label2.Text = "Sipariş Takip Numarasınız : "+dt.Rows[0][0].ToString();
 }
开发者ID:rahmisacal,项目名称:web_minning,代码行数:32,代码来源:siparisformu.aspx.cs

示例3: onClick_login

    protected void onClick_login(object sender, EventArgs e)
    {
        connection = new OleDbConnection(path);
        connection.Open();

        cmd = new OleDbCommand("SELECT COUNT(*) FROM tblProfiles WHERE user_name = '" + inputUsername.Text + "';", connection);
        cmd.ExecuteNonQuery();

        int compareUsername = Convert.ToInt32(cmd.ExecuteScalar().ToString());

        connection.Close();

        if (compareUsername == 1)
        {
            connection.Open();

            cmd = new OleDbCommand("SELECT user_password FROM tblProfiles WHERE user_name = '" + inputUsername.Text + "';", connection);
            cmd.ExecuteNonQuery();

            string comparePassword = cmd.ExecuteScalar().ToString();

            connection.Close();

            if (comparePassword == inputPassword.Text)
            {
                Session["username"] = inputUsername.Text;
                Server.Transfer("main.aspx");
            }
            else
                errorPassword.Visible = true;
        }
        else
            errorUsername.Visible = true;
    }
开发者ID:mteolis,项目名称:ecAss1,代码行数:34,代码来源:index.aspx.cs

示例4: Main

        //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();
        }
开发者ID:krstan4o,项目名称:TelerikAcademy,代码行数:39,代码来源:Program.cs

示例5: AddUser_Click

        private void AddUser_Click(object sender, EventArgs e)
        {
            comboBox1.SelectedItem = "caissier";
            string newuser = textBox1.Text;
            string newmdp = textBox2.Text;
            string test = "select username from Users where username='" + textBox1.Text + "'";
            OleDbConnection userhandlingconn = new OleDbConnection(connexionstring);
            OleDbCommand cmduserhandling = new OleDbCommand();

            try
            {

                if (textBox1.Text.Length ==0 || textBox2.Text.Length ==0|| comboBox1.SelectedItem.ToString().Length ==0)
                {
                    MessageBox.Show("Un ou plusieur champs sont vides !!!");
                }

                else
                {
                    try
                    {
                        cmduserhandling = new OleDbCommand(test, userhandlingconn);
                        userhandlingconn.Open();
                        string verif = cmduserhandling.ExecuteScalar().ToString();
                        userhandlingconn.Close();
                        if (verif.Length > 0)
                        {
                            MessageBox.Show("Cet utilisateur existe deja dans la base de données");
                        }

                    }
                    catch (NullReferenceException)
                    {
                        userhandlingconn.Close();
                        string adduser = "INSERT INTO Users ( username, [password], last_connexion, type_user ) values ('" + newuser + "','" + newmdp + "',Date(),'" + comboBox1.SelectedItem.ToString() + "');";
                        userhandlingconn.Open();
                        cmduserhandling = new OleDbCommand(adduser, userhandlingconn);
                        cmduserhandling.ExecuteNonQuery();
                        MessageBox.Show("Ajout effectué");
                        userhandlingconn.Close();
                    }

                }
            }
            catch(Exception ex)
            {
                //MessageBox.Show("Erreur !!!");
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                textBox1.Text = "";
                textBox2.Text = "";
                comboBox1.SelectedItem = "";
                DataReload();
            }
        }
开发者ID:diopisemou,项目名称:GitHub,代码行数:57,代码来源:UserHandlingForm.cs

示例6: btnLogin_Click

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        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 checkUser = "select count(*) from UserData where UserName='" + txtUserName.Text + "'";
        
        OleDbCommand com = new OleDbCommand(checkUser, conn);
        
        
        int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
        conn.Close();
        if (temp == 1)
        {
            conn.Open();
            string checkPassword = "select password from UserData where UserName='" + txtUserName.Text + "'";
            
            OleDbCommand passcom = new OleDbCommand(checkPassword, conn);
            
            string password = passcom.ExecuteScalar().ToString().Replace(" ", "");


            string checkAdmin = "select usergroup from UserData where UserName='" + txtUserName.Text + "'";
            OleDbCommand usercon = new OleDbCommand(checkAdmin, conn);
            int veriAdmin =Convert.ToInt32( usercon.ExecuteScalar().ToString());

           // conn.Close();
            if (password == txtPass.Text && veriAdmin == 1)
            {
                
                
                //if (veriAdmin == "admin")
                //{
                    Session["UserName"] = txtUserName.Text;
                    Response.Write("Login Successful! Welcome " + Session["UserName"] + "!");
              
                    
                    
                  //  Response.Redirect("~/Admin/Intro.aspx");
                    Response.AppendHeader("Refresh", "3;url=Intro.aspx");
            }
            else
            {
                Response.Write("Password is incorrect");
            }
        }
        else
        {
            Response.Write("User Name is incorrect");
        }


    }
开发者ID:bhrushank,项目名称:quality-bags-asp.net-application,代码行数:55,代码来源:Adminlogin.aspx.cs

示例7: DeleteArea

        // Completely Remove an Area from the database.
        public static void DeleteArea(int iAreaID)
        {
            // Configure database connection elements.
            OleDbDataAdapter da = new OleDbDataAdapter();

            OleDbConnection connection = new OleDbConnection();
            connection.ConnectionString = database.getConnectionString();

            // Delete All Rooms in the Area.
            try
            {
                connection.Open();

                // Create query.
                string strSQL = string.Empty;
                strSQL += " delete ";
                strSQL += " from   [Room] ";
                strSQL += " where  [RoomAreaID] = " + iAreaID.ToString() + " ";

                da.InsertCommand = new OleDbCommand(strSQL);
                da.InsertCommand.Connection = connection;

                da.InsertCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                string strError = ex.Message;
            }
            connection.Close();

            // Delete the Area.
            try
            {
                connection.Open();

                // Create query.
                string strSQL = string.Empty;
                strSQL += " delete ";
                strSQL += " from   [Area] ";
                strSQL += " where  [AreaID] = " + iAreaID.ToString() + " ";

                da.InsertCommand = new OleDbCommand(strSQL);
                da.InsertCommand.Connection = connection;

                da.InsertCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                string strError = ex.Message;
            }

            connection.Close();
            connection.Dispose();
        }
开发者ID:kerchunk,项目名称:GizMaker,代码行数:55,代码来源:area.cs

示例8: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            
            string chaine = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/dhib/Desktop/Professeur.accdb";
            OleDbConnection con = new OleDbConnection(chaine);
            OleDbCommand cmd = con.CreateCommand();
            OleDbCommand cmd1 = con.CreateCommand();

            cmd.CommandText = "Insert into etudiant values (" + Convert.ToInt32(txt_cin.Text) + ",'" + txt_nom.Text + "','" + txt_prenom.Text + "','" + comboBox1.Text + "')";
            

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                MessageBox.Show("Ajout Module Réussi");
                con.Close();

                new acceuil(login).Show();
                this.Hide();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur" + ex.Message);
                con.Close();
            }



            //ckecked lisT 
             foreach(object itemChecked in checkedListBox1.CheckedItems) {
                 cmd1.CommandText = "Insert into assiste(cin,id_module,date_present) values(" + Convert.ToInt32(txt_cin.Text) + "," + hash[(string)itemChecked] + ",'" + DateTime.Now.ToString("dd-MM-yyyy") + "')";
                 try
                 {
                     con.Open();
                     cmd1.ExecuteNonQuery();
                     con.Close();


                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("Erreur" + ex.Message);
                     con.Close();
                 }
             }





        }
开发者ID:Marioum,项目名称:C-sharp-mini-project,代码行数:53,代码来源:nouveau_etudiant.cs

示例9: LoadData

    protected void LoadData()
    {
        string strsql = "select * from customers where custnumber = " + Session["custid"];
        OleDbConnection myConn = new OleDbConnection();
        myConn.ConnectionString = System.Web.Configuration.WebConfigurationManager.
        ConnectionStrings["AcmeShoppeConnectionString"].ConnectionString;
        OleDbCommand myCmd = new OleDbCommand(strsql, myConn);
        OleDbDataReader myReader;
        if (myConn.State == ConnectionState.Closed) myConn.Open();
            myReader = myCmd.ExecuteReader();

            if (myReader.HasRows)
            {
                myReader.Read();
                this.lblFName.Text = myReader["FirstName"].ToString();
                this.lblLName.Text = myReader["LastName"].ToString();
                this.txtAddress.Text = myReader["Address"].ToString();
                this.txtCity.Text = myReader["City"].ToString();
                this.txtZip.Text = myReader["ZipCode"].ToString();
                this.DropDownList1.SelectedValue = myReader["State"].ToString();
            }
            else
                this.lblerr.Text = "error";
         myReader.Close();
         myCmd.CommandText = "select sum(extension) from cart_view01 " +
                                    "where cartnumber = " + Session["cartnumber"];
         decimal decSubtotal = 0;
         double decSalesTax = 0;
         double decTotal = 0;
         double decShip = 3.25;
         if (myConn.State == ConnectionState.Closed) myConn.Open();
         myReader = myCmd.ExecuteReader();
         if (myReader.HasRows)
         {
             myReader.Read();
             if (myReader[0] != DBNull.Value)
             {
                 decSubtotal = Convert.ToDecimal(myReader[0].ToString());
                 this.lblSubtotal.Text = decSubtotal.ToString("c");
             }
             decSalesTax = Convert.ToDouble(decSubtotal) * .05;
             Math.Round(decSalesTax, 2);
             decTotal = Convert.ToDouble(decSubtotal) + decSalesTax + decShip;
             Math.Round(decTotal, 2);
             this.lblTax.Text = decSalesTax.ToString("c");
             this.lblTotal.Text = decTotal.ToString("c");
             this.lblShipping.Text = decShip.ToString("c");
         }
         else
             this.lblerr.Text = "error";
         myConn.Close();
    }
开发者ID:aruntosa,项目名称:Client-Server-Final-Project-C-Sharp,代码行数:52,代码来源:Checkout.aspx.cs

示例10: Excel2Dataset

        public static System.Data.DataSet Excel2Dataset(string fileName, string tableName)
        {
            bool isOpen = true;
            try
            {
                return DataSet2CSV.ConverCSV2DataSet(fileName, tableName);
            }
            catch (System.Exception) { }

            OleDbConnection connStr = new OleDbConnection();
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'";
            connStr.ConnectionString = strConn;
            try
            {
                connStr.Open();
            }
            catch (System.Exception)
            {
                isOpen = false;
            }

            if (!isOpen)
            {
                isOpen = true;
                strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties='Excel 12.0 Xml;HDR=YES';";
                connStr.ConnectionString = strConn;
                try
                {
                    connStr.Open();
                }
                catch (System.Exception)
                {
                    isOpen = false;
                }
            }

            if (!isOpen)
                return null;

            //动态表名
            DataTable tblSchema = connStr.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
            string sheetName = tblSchema.Rows[0]["TABLE_NAME"].ToString();
            OleDbDataAdapter cmd = new OleDbDataAdapter("select * from [" + sheetName + "]", connStr);

            DataSet ds = new DataSet();
            cmd.Fill(ds, tableName);

            connStr.Close();
            connStr = null;
            return ds;
        }
开发者ID:yalunwang,项目名称:family,代码行数:51,代码来源:DataSet2Excel.cs

示例11: BtnSave_Click

    protected void BtnSave_Click(object sender, EventArgs e)
    {
        if (MainMenu.SelectedValue.ToString() == "")
        {
            LblError.Text = "من فضلك قم بأختيار خيار من القائمه";
            LblError.ForeColor = System.Drawing.Color.Red;
            LblError.Visible = true;
        }
        string Path = string.Empty;
        OleDbConnection Con = new OleDbConnection(constr);
        OleDbCommand CMD = new OleDbCommand("SELECT Data_Path FROM MenuItem Where ItemID = " + MainMenu.SelectedValue.ToString(), Con);
        try
        {
            Con.Open();
            Path = CMD.ExecuteScalar().ToString();

        }
        catch { }
        Con.Close();
        if (Path == string.Empty)
        {
            //Path = MapPath("~/QAData/QAData" + QAMainMenu.SelectedValue.ToString() + ".QA");
            Path = String.Format("../ItemData/Data{0}{1}{2}{3}.Dat", MainMenu.SelectedValue, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
        }
        try
        {
            CMD.CommandText = String.Format("Update MenuItem Set Data_Path = '{0}' Where ItemID = {1}", Path, MainMenu.SelectedValue);
            Con.Open();
            CMD.ExecuteNonQuery();
            Path = MapPath(Path);
            //if (File.Exists(Path))
            //{
            //    File.Delete(Path);
            //}
            File.Create(Path).Close();
            TextWriter TW = new StreamWriter(Path, false);
            TW.Write(Request.Form["editor1"]);
            TW.Flush();
            TW.Close();
            LblError.Text = "تم الحفــــظ";
            LblError.ForeColor = System.Drawing.Color.Green;
            LblError.Visible = true;
        }
        catch (Exception ex)
        {
            LblError.Text = ex.Message.ToString();
            LblError.ForeColor = System.Drawing.Color.Red;
            LblError.Visible = true;
        }
        Con.Close();
    }
开发者ID:EgyFalseX,项目名称:WebSites,代码行数:51,代码来源:CreatePages.ascx.cs

示例12: GetExcelDistictBTNCOunt_Sales

    public int GetExcelDistictBTNCOunt_Sales(string sFileName)
    {
        Int32 NORec;
        DataSet objDataset1 = new DataSet();
        int count = 0;
        OleDbConnection objConn = new OleDbConnection();
        try
        {
             string FileExt = System.IO.Path.GetExtension(sFileName);
             if (FileExt == ".xls")
             {
                 //Excell connection
                 string Xls_Con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sFileName + ";Extended Properties=\"Excel 8.0;HDR=YES; IMEX=1;ImportMixedTypes=Text\"";
                 objConn.ConnectionString = Xls_Con;
                 //Dim objConn As New OleDbConnection(Xls_Con)
                 objConn.Open();
                 DataTable ExcelSheets = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
                 string SpreadSheetName = "[" + ExcelSheets.Rows[0]["TABLE_NAME"].ToString() + "]";

                 OleDbDataAdapter objAdapter1 = new OleDbDataAdapter("SELECT distinct(Phoneno) FROM " + SpreadSheetName, objConn);
                 objAdapter1.Fill(objDataset1, "XLData");

                 count = Convert.ToInt32(objDataset1.Tables[0].Rows.Count);
             }
             else if (FileExt == ".xlsx")
             {
                 //Excell connection
                 string Xls_Con = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sFileName + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                 objConn.ConnectionString = Xls_Con;
                 //Dim objConn As New OleDbConnection(Xls_Con)
                 objConn.Open();
                 DataTable ExcelSheets = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
                 string SpreadSheetName = "[" + ExcelSheets.Rows[0]["TABLE_NAME"].ToString() + "]";

                 OleDbDataAdapter objAdapter1 = new OleDbDataAdapter("SELECT distinct(Phoneno) FROM " + SpreadSheetName, objConn);
                 objAdapter1.Fill(objDataset1, "XLData");

                 count = Convert.ToInt32(objDataset1.Tables[0].Rows.Count);
             }
            objConn.Close();
        }
        catch (Exception ex)
        {
            throw ex;
            //Redirecting to error message page

            // Redirect(ConstantClass.StrErrorPageURL);
        }
        return count;
    }
开发者ID:BInny1,项目名称:newcarsales,代码行数:50,代码来源:ExcelReading.cs

示例13: BtnSave_Click

    protected void BtnSave_Click(object sender, EventArgs e)
    {
        string Path = string.Empty;
        OleDbConnection Con = new OleDbConnection(constr);
        OleDbCommand CMD = new OleDbCommand("SELECT Contain FROM NewsData Where ID = " + Request.QueryString["ID"].ToString(), Con);
        try
        {
            Con.Open();
            Path = CMD.ExecuteScalar().ToString();

        }
        catch { }
        Con.Close();
        if (Path == string.Empty)
        {
            //Path = MapPath("~/QAData/QAData" + QAMainMenu.SelectedValue.ToString() + ".QA");
            if (!Directory.Exists(MapPath("../ItemData/")))
            {
                Directory.CreateDirectory(MapPath("../ItemData/"));
            }
            Path = String.Format("../ItemData/Data{0}{1}{2}{3}.Dat", Request.QueryString["ID"], DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
        }
        try
        {
            CMD.CommandText = String.Format("Update NewsData Set Contain = '{0}' Where ID = {1}", Path, Request.QueryString["ID"]);
            Con.Open();
            CMD.ExecuteNonQuery();
            Path = MapPath(Path);
            //if (File.Exists(Path))
            //{
            //    File.Delete(Path);
            //}
            File.Create(Path).Close();
            TextWriter TW = new StreamWriter(Path, false);
            TW.Write(txt1.Html);
            TW.Flush();
            TW.Close();
            LblError.Text = "تم الحفــــظ";
            LblError.ForeColor = System.Drawing.Color.Green;
            LblError.Visible = true;
        }
        catch (Exception ex)
        {
            LblError.Text = ex.Message.ToString();
            LblError.ForeColor = System.Drawing.Color.Red;
            LblError.Visible = true;
        }
        Con.Close();
    }
开发者ID:EgyFalseX,项目名称:WebSites,代码行数:49,代码来源:CreatePages.ascx.cs

示例14: GetDataFromExcel

        public static List<Dictionary<string, string>> GetDataFromExcel(string FilePath, string Extension, string isHDR)
        {
            var list = new List<Dictionary<string, string>>();

            string conStr = "";
            switch (Extension)
            {
                case ".xls": //Excel 97-03
                    conStr = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
                    break;
                case ".xlsx": //Excel 07
                    conStr = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
                    break;
            }
            conStr = String.Format(conStr, FilePath, isHDR);
            OleDbConnection connExcel = new OleDbConnection(conStr);
            OleDbCommand cmdExcel = new OleDbCommand();
            OleDbDataAdapter oda = new OleDbDataAdapter();
            DataTable dt = new DataTable();
            cmdExcel.Connection = connExcel;

            //Get the name of First Sheet
            connExcel.Open();
            DataTable dtExcelSchema;
            dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
            connExcel.Close();

            //Read Data from First Sheet
            connExcel.Open();
            cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
            oda.SelectCommand = cmdExcel;
            oda.Fill(dt);
            connExcel.Close();

            foreach (DataRow row in dt.Rows)
            {
                var obj = new Dictionary<string, string>();
                foreach (var col in dt.Columns)
                {
                    var key = Regex.Replace(col.ToString(), @"\s+", "");
                    obj.Add(key, row[col.ToString()].ToString());
                }
                list.Add(obj);
            }

            return list;
        }
开发者ID:bkferareza,项目名称:DarthMaul,代码行数:48,代码来源:ExcelHelper.cs

示例15: count

    public void count()
    {
        OleDbConnection conn = new OleDbConnection(connstr);
        OleDbCommand cmdread = new OleDbCommand("SELECT count FROM main WHERE id=1", conn);
        try
        {
            conn.Open();
            p = (int)cmdread.ExecuteScalar();
            conn.Close();
            label1.Text = p.ToString();
            if (p < 10)
                label1.Text = "000" + label1.Text;
            else if (p < 100)
                label1.Text = "00" + label1.Text;
            else if (p < 1000)
                label1.Text = "0" + label1.Text;

            if ((int)Application["numVisitors"] != 0)
            {
                c = (int)Application["numVisitors"];
                int r = p + c;

                OleDbCommand cmd = new OleDbCommand("UPDATE main SET [count][email protected]", conn);  /*"UPDATE main SET [count][email protected] WHERE [id]=1"*/

                cmd.Parameters.AddWithValue("count", r);

                /*p = (int)cmd.Parameters.AddWithValue("@count", 4).Value;*/

                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();

                label1.Text = r.ToString();
                if (r < 10)
                    label1.Text = "000" + label1.Text;
                else if (r < 100)
                    label1.Text = "00" + label1.Text;
                else if (r < 1000)
                    label1.Text = "0" + label1.Text;

                Application["numVisitors"] = 0;
            }
        }
        finally
        {
            conn.Close();
        }
    }
开发者ID:madmax17,项目名称:NBA-Greatest-Dunkers,代码行数:48,代码来源:default.aspx.cs


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