vs.net2003 和sql2000用于连接的连接字符串怎么写。写的具体些(vb.net环境)
vs.net2003 和sql2000用于连接的连接字符串怎么写
- 提问者网友:且恨且铭记
- 2021-04-30 13:34
- 五星知识达人网友:有你哪都是故乡
- 2021-04-30 14:19
//数据库连接 Initial Catalog=pubs 填数据库名称,;User ID=sa 填用户名
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=.";
myConn.Open();
//对数据表student进行查询操作。把里面的内容显示出来
string sqlStr = "select * from jobs";
SqlCommand myCmd = new SqlCommand(sqlStr, myConn);
SqlDataReader dr = myCmd.ExecuteReader();
while (dr.Read())
{
Response.Write(dr[1].ToString() + "<br>");
}
myConn.Close();
- 1楼网友:千夜
- 2021-04-30 15:08
- 2楼网友:一袍清酒付
- 2021-04-30 14:31
namespace Tool_Manage //创建类 { public class py //类名:py { public static SqlConnection getConn() { SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=TMDB;Persist Security Info=True;User ID=sa;Password=854638"); //链接数据库 return conn;//返回 } } }
在窗口后台代码中就可以实现访问数据库了
protected void Button1_Click(object sender, EventArgs e) { if (this.IsValid) { SqlConnection conn = py.getConn(); conn.Open(); string sql = string.Format("INSERT INTO User_(yuangongbianhao ,dengluming ,denglumima ,jueseming ,xingbie,shifouyouxiao )VALUES('" + this.txtid.Text + "','" + this.txtusername.Text + "','" + this.txtuserpwd.Text + "','" + this.DropDownList1.SelectedValue + "','男','0')"); SqlCommand cmd = new SqlCommand(sql, conn); DataSet ds = new DataSet(); SqlDataAdapter sqlApt = new SqlDataAdapter(cmd); sqlApt.Fill(ds); conn.Close(); this.Session["code1"] = this.txtusername.Text.Trim(); Response.Write("<script>alert('注册成功,请完善个人登录信息!');window.window.location.href='updateyhxx.aspx';</script>");
} else {
} }