我的SQL服务器用的本地系统身份验证,
我创建了book数据库,它有表T1 (ID,Name,QQ,Mes)和 表T2(admin,PWD)
我使用GridView控件,配置数据源,它在我的web.config里面加入了 数据库连接字符串,代码如下:
数据能正确显示,现在我添加了另一个页Default.aspx
带有3个TextBox,和一个"提交“按钮,想把填写在3个TEXTBOX里面的内容插入到数据表T1里面,但怎么也插不进去,也没有提示出错误,救命哦~~
,提交数据的代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected string strCon = "Data Source=PC-05301323;Initial Catalog=book;Integrated Security=True";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BT1_Click(object sender, EventArgs e)
{
SqlConnection sqlConn = new SqlConnection(strCon);
string str = "INSERT INTO T1(Name,QQ,Mes) VALUES('"+ TB1.Text.Trim() + "','" + TB2.Text.Trim() +" ','"+ TB3.Text+"')";
sqlConn.Open();
SqlCommand sqlComm = new SqlCommand(str, sqlConn);
this.Label1.Text = "数据插入成功";
sqlConn.Close();
Response.Redirect("Default2.aspx?message=数据显示");
}
}
大侠们,班我看看是哪里出了问题。。。。。,我估计是连接字符串有问题,那么如果我想引用web.config里面的connectionStrings,name="bookConnectionString",该如何做,在线等。。。。