推薦:解析兩種ASP.Net數據庫連接設置和讀取方法在這里我們介紹兩種ASP.Net數據庫連接設置和讀取方法:web.config文件和Gloab文件。 方法一:web.config文件 ――設置: 在web.config文件里添加關鍵字key是通過appSettings標記來實現的,但是appSettings標記通常放在system.web...../system.web標記外面。
辦公軟件Excel是一種常用的電子表格軟件,在編程項目中有需要將Excel轉換為SQL Server數據庫的需求,本文對此進行一些介紹并給出設計代碼。| string strOdbcCon = @"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=D:/2010年圖書銷售情況.xls;Extended Properties=Excel 8.0"; |
| public void LoadData(string StyleSheet) { string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + Server.MapPath ("usersdb.xls") + ";Extended Properties=Excel 8.0"; OleDbConnection myConn = new OleDbConnection(strCon); myConn.Open(); //打開數據鏈接,得到一個數據集 DataSet myDataSet = new DataSet(); //創建DataSet對象 string StrSql = "select * from [" + StyleSheet + "$]"; OleDbDataAdapter myCommand = new OleDbDataAdapter(StrSql, myConn); myCommand.Fill(myDataSet, "[" + StyleSheet + "$]"); myCommand.Dispose(); DataTable DT = myDataSet.Tables["[" + StyleSheet + "$]"]; myConn.Close(); myCommand.Dispose(); string strConn = "Data Source=(local);DataBase=Usersdb;Uid=sa;Pwd="; SqlConnection conn = new SqlConnection(strConn); conn.Open(); for (int j = 0; j < DT.Rows.Count; j++) { string UserID = DT.Rows[j][0].ToString(); string EmailAddress = DT.Rows[j][1].ToString(); string FirstName = DT.Rows[j][2].ToString(); string LastName = DT.Rows[j][3].ToString(); string Address1 = DT.Rows[j][4].ToString(); string Address2 = DT.Rows[j][5].ToString(); string City = DT.Rows[j][6].ToString(); string strSql = "insert into Usersdb(EmailAddress,FirstName, LastName,Address1,Address2,City) "; strSql = strSql + "values(’" + EmailAddress + "’,’" + FirstName + "’, ’" + LastName + "’,’" + Address1 + "’,’" + Address2 + "’,’" + City + "’)"; SqlCommand comm = new SqlCommand(strSql, conn); comm.ExecuteNonQuery(); if (j == DT.Rows.Count - 1) { Label1.Visible = true; } else { Label1.Visible = false; } } conn.Close(); } |
| protected void Button1_Click(object sender, EventArgs e) { string StyleSheet = "Sheet1"; LoadData(StyleSheet); } |
| protected void Button2_Click(object sender, EventArgs e) { string strConn = "Data Source=(local);DataBase=Usersdb;Uid=sa;Pwd="; string sqlstr="select * from Usersdb"; SqlConnection conn = new SqlConnection(strConn); SqlDataAdapter myda = new SqlDataAdapter(sqlstr,conn); DataSet ds = new DataSet(); conn.Open(); myda.Fill(ds, "Usersdb"); GridView1.DataSource = ds; GridView1.DataBind(); conn.Close(); } |
分享:GridView/DataGrid行單擊和雙擊事件實現代碼功能: 單擊選中行,雙擊打開詳細頁面 說明: 單擊事件(onclick)使用了setTimeout延遲,根據實際需要修改延遲時間 當雙擊時,通過全局變量dbl_click來取消單擊事件的響應 常見處理行方式會選擇在RowDataBound/ItemDataBound中處理,這里我選擇Page.Render中
新聞熱點
疑難解答
圖片精選