永发信息网

vs.net2003 和sql2000用于连接的连接字符串怎么写

答案:3  悬赏:10  手机版
解决时间 2021-05-01 01:13
  • 提问者网友:且恨且铭记
  • 2021-04-30 13:34

vs.net2003 和sql2000用于连接的连接字符串怎么写。写的具体些(vb.net环境)

最佳答案
  • 五星知识达人网友:有你哪都是故乡
  • 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
server=.;database=数据库名;uid=sa;pwd=;
  • 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     {

    }     }

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯