首页上一页 1 下一页尾页 1 条记录 1/1页
添加数据不成功
发表在C#图书答疑
2008-12-13
是否精华
是
否
版块置顶:
是
否
老师你好:
我在做5.3.2练习的时候
向数据库中添加数据,老是不成功;调试没什么错误提示
麻烦你帮我看下,谢了!
代码
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
this.bind();
}
}
public void bind()
{
string strcon = "Data Source=WWW-ASUS\\SQLEXPRESS;Initial Catalog=student;Integrated Security=True";
string strcom = "select * from student";
SqlConnection mycon = new SqlConnection(strcon);
mycon.Open();
SqlDataAdapter myda = new SqlDataAdapter(strcom,mycon);
DataSet myds = new DataSet();
myda.Fill(myds,"student");
GridView1.DataSource = myds;
GridView1.DataBind();
mycon.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
string strcon = "Data Source=WWW-ASUS\\SQLEXPRESS;Initial Catalog=student;Integrated Security=True";
string strcom = "insert into student(id,grade) values('"+TextBox1.Text.Trim()+"','"+TextBox2.Text.Trim()+"')";
SqlConnection sqlcon = new SqlConnection(strcon);
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand(strcom,sqlcon);
sqlcom.ExecuteNonQuery();
sqlcon.Close();
this.bind();
}
}
我在做5.3.2练习的时候
向数据库中添加数据,老是不成功;调试没什么错误提示
麻烦你帮我看下,谢了!
代码
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
this.bind();
}
}
public void bind()
{
string strcon = "Data Source=WWW-ASUS\\SQLEXPRESS;Initial Catalog=student;Integrated Security=True";
string strcom = "select * from student";
SqlConnection mycon = new SqlConnection(strcon);
mycon.Open();
SqlDataAdapter myda = new SqlDataAdapter(strcom,mycon);
DataSet myds = new DataSet();
myda.Fill(myds,"student");
GridView1.DataSource = myds;
GridView1.DataBind();
mycon.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
string strcon = "Data Source=WWW-ASUS\\SQLEXPRESS;Initial Catalog=student;Integrated Security=True";
string strcom = "insert into student(id,grade) values('"+TextBox1.Text.Trim()+"','"+TextBox2.Text.Trim()+"')";
SqlConnection sqlcon = new SqlConnection(strcon);
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand(strcom,sqlcon);
sqlcom.ExecuteNonQuery();
sqlcon.Close();
this.bind();
}
}