注册 登录
编程论坛 ASP.NET技术论坛

高手帮忙看下,asp.net写的.数据库为什么不能更新?

tc1937 发布于 2011-04-27 15:39, 717 次点击
protected void Submit_Click(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection("server=localhost ;uid=sa;pwd=sa;database=HotelManagement");
        string n = "select top (1) UserID from Login order by UserID desc";
        SqlCommand cmd = new SqlCommand(n, cn);
        cn.Open();
        SqlDataReader sdr = cmd.ExecuteReader();
        sdr.Read();
        int a = (int)sdr["UserID"];
        int b;
        b = a + 1;
        string s = "";
        if (RadioButton1.Checked)
            s = "男";
        else if (RadioButton2.Checked)
            s = "女";
        
        SqlCommand cm = new SqlCommand("insert into Customers(UserID,CName,CAge,CSex,CPhone) values('" + b + "','" + this.TextBox1.Text + "','" + this.TextBox4.Text + "','" + s + "','" + this.TextBox8.Text + "'", cn);
        SqlDataAdapter da = new SqlDataAdapter(cm);
        
      
    }
6 回复
#2
jalonlovesja2011-04-28 08:29
这是全部代码吗?
是不是少了"da.Fill()"?
#3
girl00012011-04-29 22:17
更新操作应该不需要SqlDataAdapter da = new SqlDataAdapter(cm);
直接cm.ExecuteNonQuery();cn.Close();
#4
eEyo2011-05-03 10:10
你的insert语句没有执行。
楼上说的对。
#5
yms1232011-05-03 15:18
没写更新代码
#6
jiasenlin2011-05-12 11:45
SqlCommand cm = new SqlCommand("insert into Customers(UserID,CName,CAge,CSex,CPhone) values('" + b + "','" + this.TextBox1.Text + "','" + this.TextBox4.Text + "','" + s + "','" + this.TextBox8.Text + "'", cn);
        SqlDataAdapter da = new SqlDataAdapter(cm);

 更新  是      updata table  set
#7
VV程序员2011-05-13 17:08
楼主问题不明确  鉴定完毕!
1