陌上离颜终成枯 发表于 2015-5-11 14:31:52

C#连接数据库注册显示未初始化

C#连接数据库注册显示未初始化,代码如下:
protected void Button1_Click(object sender, EventArgs e)
    {
      //先获取页面信息
      string st_username = this.TextBox1.Text;
      string st_password = this.TextBox2.Text;
      string st_number = this.TextBox3.Text;
      string st_name = this.TextBox4.Text;
      string st_department = this.TextBox5.Text;
      string st_class = this.TextBox6.Text;
      //获得连接数据库字符串
      string conn = "Data Source=PC-20140706QNKM;Initial Catalog=Management;Integrated Security=True";
      //创建sqlconnection对像
      SqlConnection connection = new SqlConnection(conn);
      //打开数据库
      connection.Open();
      //创建一个数据库命令行
      SqlCommand Command = new SqlCommand(conn);
      Command.CommandText = "insert into student(st_username,st_password,st_number,st_name,st_department,st_class)values(@st_username,@st_password,@st_number,@st_name,@st_department,@st_class)";
      Command.Parameters.AddWithValue("@st_username", TextBox1);
      Command.Parameters.AddWithValue("@st_password", TextBox2);
      Command.Parameters.AddWithValue("@st_number", TextBox3);
      Command.Parameters.AddWithValue("@st_name", TextBox4);
      Command.Parameters.AddWithValue("@st_department", TextBox5);
      Command.Parameters.AddWithValue("@st_class", TextBox6);
      //执行数据库命令
      Command.ExecuteNonQuery();
      //提示注册成功
      Label1.Text = "注册成功";
      //清空输入框
      TextBox1.Text = "";
      TextBox2.Text = "";
      TextBox3.Text = "";
      TextBox4.Text = "";
      TextBox5.Text = "";
      TextBox6.Text = "";
      //关闭命令和链接
      Command.Dispose();
    }

ibcadmin 发表于 2015-5-14 09:24:42

具体错误信息是什么, 如果是未初始化的话 跟你的config有关系,但是看你代码 应该是跟config没关系
页: [1]
查看完整版本: C#连接数据库注册显示未初始化