推荐:解析两种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中
新闻热点
疑难解答
图片精选