已有56人关注
添加数据不成功
发表在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();
    }
}
分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2008-12-13
沙发
读者朋友:
    您好,在string strcom = "insert into student(id,grade) values('"+TextBox1.Text.Trim()+"','"+TextBox2.Text.Trim()+"')";这条语句这插入断点,然后执行到这块之后,把这个字符串复制下来到SQL查询分析器里面执行一下,看好不好使,别的地方没有错误。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照