马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

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

  [复制链接]
查看6274 | 回复1 | 2015-5-11 14:31:52 | 显示全部楼层 |阅读模式
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没关系
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则