SQLCommand中的语句是
INSERT INTO studentTable
      (studentId, studentName, password, roomNumber, telephone, QQ, studentSex, 
      [E-Mail])
VALUES ('@studentId', '@studentName', '@password', '@roomNumber', '@telephone', 
      '@QQ', '@studentSex', '@E-Mail')
保存按钮的代码是
cmd.Parameters["@studentId"].Value = txtstuId.Text;
cmd.Parameters["@studentName"].Value = txtstuName.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
但是就是不能把记录保存到数据库中 
哪里有问题啊!
请各位帮帮忙  谢谢!

解决方案 »

  1.   

    使用语句:cmd.Parameters.Add("@studentId",txtstuId.Text);
    INSERT INTO studentTable
          (studentId, studentName, password, roomNumber, telephone, QQ, studentSex, 
          [E-Mail])
    VALUES (@studentId, @studentName, @password, @roomNumber, @telephone, 
          @QQ, @studentSex, @E-Mail)
    @XXXX不需要用单引号就可以做了
    还有你怎么就插两个字段?即使插两个字段你就应该在insert语句中就写两个 要不会和数据库冲突
      

  2.   

    找段正确的插入代码看看吧,你这应该是参数错误
    问题不大
    给你一段代码吧.不是用参数的,我感觉方便一点
    insert into userlogin (username,userpassword,usersex,usereducation,userschool) values('"+this.txtusername .Text .Trim ()+"','"+this.txtpassword .Text .Trim ()+"','"+this.sex +"','"+this.dpdlistxueli .SelectedValue +"','"+this.txtgraduate .Text .Trim ()+"')
      

  3.   

    dropdownlist没有文本输入框框的,我想用层做一个输入框框,我的dropdownlist是动态生成的,这个时候我就要将层移动到dropdownlist上去。请问我怎么获取dropdownlist的坐标值,然后让层覆盖该dropdownlist?
    以下帖子给分。
    如何在C#.net WEB2005开发中获取dropdownlist在网页中的位置坐标?
    http://community.csdn.net/Expert/topic/5481/5481151.xml?temp=.4136316
    救救我。
      

  4.   

    dropdownlist没有文本输入框框的,我想用层做一个输入框框,我的dropdownlist是动态生成的,这个时候我就要将层移动到dropdownlist上去。请问我怎么获取dropdownlist的坐标值,然后让层覆盖该dropdownlist?
    以下帖子给分。
    如何在C#.net WEB2005开发中获取dropdownlist在网页中的位置坐标?
    http://community.csdn.net/Expert/topic/5580/5580708.xml?temp=.7489435
    昨天晚上发错连接,更正在发送。
      

  5.   

    没有研究过 con.open()应该写在什么地方,自己学的也不太好,只知道,放在存储参数前面更保险。。
      

  6.   

    SQLCommand中的语句是
    INSERT INTO studentTable
          (studentId, studentName, password, roomNumber, telephone, QQ, studentSex, 
          [E-Mail])
    VALUES (@studentId, @studentName, @password, @roomNumber, @telephone, @QQ, 
          @studentSex, @E - Mail)
    保存按钮的代码是
    private void Button1_Click(object sender, System.EventArgs e)
    {
    conn.Open();
    cmd.Parameters.Add("@studentId","'" + txtstuId.Text.Trim() + "'");
    cmd.Parameters.Add("@studentName","'" + txtstuName.Text.Trim() + "'");
    cmd.Parameters.Add("@password","'" + txtPassword.Text.Trim() + "'");
    cmd.Parameters.Add("@roomNumber","'" + txtroomNumber.Text.Trim() + "'");
    cmd.Parameters.Add("@telephone","'" + txtTelephone.Text.Trim() + "'");
    cmd.Parameters.Add("@QQ","'" + txtQQ.Text.Trim() + "'");
    cmd.Parameters.Add("@studentSex","'" + DropDownList1.SelectedValue + "'");
    cmd.Parameters.Add("@E-Mail","'" + txtMail.Text.Trim() + "'");
    cmd.ExecuteNonQuery();
    conn.Close();
    }记录还是保存不到数据库,我打开事件探查器看 根本就不执行 update 语句
    是什么原因阿?
    大家再帮忙看看!谢谢!
      

  7.   

    cmd.Parameters.Add("@studentId",txtstuId.Text);
    你加那些单引号多余 这里不是加到sql语句 而是参数赋值
      

  8.   

    没办法了 可能你数据库里的表有点问题 仔细看看字段是否一致 下面是我做的项目的一段差不多的代码:cmd=new SqlCommand("Update Users set Password=@Password where UserName=@UserName",cn);
    cmd.Parameters.Add("@UserName",this.txtUser.Text);
    cmd.Parameters.Add("@Password",this.txtPwd.Text);
    try
    {
    cn.Open();
    cmd.ExecuteNonQuery();
    ds.Clear();
    da.Fill(ds,"Users");
    MessageBox.Show("修改成功!");
    this.txtUser.Clear();
    this.txtPwd.Clear();
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    finally
    {
    cn.Close();
    }