sqlInsertCommand1.CommandText="INSERT INTO (用户) VALUES(textBxo1.tText)"

解决方案 »

  1.   

    sqlInsertCommand1.CommandText="INSERT INTO (用户) VALUES('" + textBxo1.tText + "')"
      

  2.   

    请你设置断点,输出你的sqlInsertCommand1.CommandText!看看是否正确!~用MessageBox.Show()方法也可以!
      

  3.   

    看你代码是在哪儿写的
    1点提交的之前你是否在LOAD里面单独设置过textbox1="",而没有写在ispostback里面
    2:最好还是把SQL语句写全
    insert into yonghu(字段1,字段2) values (textbox,textbox2)
      

  4.   

    sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUES('"+textBxo1.tText',"+"'textBox2.Text+')"
      

  5.   

    举个例子
    cmd=new SqlCommand("insert into info (name,phone) values(@name,@phone)",cn);
    cmd.Parameters.Add("@name",SqlDbType.VarChar,50);
    cmd.Parameters.Add("@phone",SqlDbType.VarChar,10);
    cmd.Parameters[0].Value=textBox1.tText;
    cmd.Parameters[1].Value=textBox2.Text;
    cmd.ExecuteNonQuery();
      

  6.   

    这是我的代码,是一个添加用户的,要求密码一致才行.
    private void button1_Click(object sender, System.EventArgs e)
    {
    sqlConnection1.Open();
    if(textBox2.Text==textBox3.Text)
    {
    sqlInsertCommand1.CommandText="INSERT INTO (用户) VALUES('" + textBox1.Text + "','" + textBox1.Text + "')";
    }
    Form1 xian1=new Form1();
    this.Hide();
    xian1.Show();
    }
    这样添加不了.
      

  7.   

    sqlInsertCommand1.CommandText=@"insert into tablename values( '" + textBox1.Text+"','"+textBox2.Text+"')";
      

  8.   

    sqlcommand cmd =new sqlcommand(strInsertCommand.commandText,sqlconnection)
    cmd.executenoquote();
      

  9.   

    zhpsam109(孤寂无边) 我按你的做了但是还是不行.
      

  10.   

    if(textBox2.Text.Trim() == textBox3.Text.Trim())试试
      

  11.   

    sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE('"+textBxo1.tText"',+'"textBox2.Text+"')"如果字段为数字的话,把'去掉
    sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE("+textBxo1.tText",+"textBox2.Text+")"
      

  12.   

    上面的错了,不好意思sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE('"+textBxo1.tText+"','"+textBox2.Text+"')"如果字段为数字的话,把'去掉
    sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE("+textBxo1.tText+","+textBox2.Text+")"
      

  13.   

    sqlInsertCommand1.CommandText 
    设置断点,取出sql语句的内容
    到数据库里直接执行你的语句,如果插入成功,则说明你的sql语句无错误,再看看其他的地方有什么问题
      

  14.   

    怎么能这样呢?
    要作字串带进去才行string.Format("INSERT TABELNAME VALUES('{0}', '{1}')", textBox1.Text, textBox2.Text)指定CommandText属性,注意要把Connection.Open()才行
      

  15.   

    同意aicode(加勒比海盗)也可以用SqlDataAdapter的Update
      

  16.   

    sqlInsertCommand1.CommandText="INSERT INTO (用户) VALUES('" + textBxo1.tText + "')"在VALUES可以声明要插入的字段。你没有显式声明哪些字段要插入,所以你必插入时须按照数据库中的实际字段数量,顺序不能错。当数据类型不匹配或数据长度超出时,插入操作会出错!
      

  17.   

    设置一个断点,把SQL语句取出,到查询分析器中去执行,看效果如何我怀疑,你的数据库里面可能有触发器,检测到插入的数据不合法,而使Insert失效。这种情况下,是不会返回错误的
      

  18.   

    是不是缺少sqlInsertCommand1.ExecuteNonQuery();这一句?
      

  19.   

    Sel_ins="insert into admin values(@ID,@username,@password,@oskey,@lastlogin)";
    SqlCommand Cmd_ins=new SqlCommand(Sel_ins,myConnection);
    Cmd_ins.Parameters.Add(new SqlParameter("@ID",SqlDbType.Int,4));
    Cmd_ins.Parameters["@id"].Value =Max_num;
    Cmd_ins.Parameters.Add(new SqlParameter("@username",SqlDbType.VarChar,16));
    Cmd_ins.Parameters["@username"].Value =username.Text;
    Cmd_ins.Parameters.Add(new SqlParameter("@password",SqlDbType.VarChar,16));
    Cmd_ins.Parameters["@password"].Value =password1.Text;
    Cmd_ins.Parameters.Add(new SqlParameter("@oskey",SqlDbType.VarChar,5));
    Cmd_ins.Parameters["@oskey"].Value =oskey.SelectedValue;
    Cmd_ins.Parameters.Add(new SqlParameter("@lastlogin",SqlDbType.DateTime,8));
    Cmd_ins.Parameters["@lastlogin"].Value =currentTime;
    //执行
    Cmd_ins.ExecuteNonQuery();
      

  20.   

    现在查询器中看看sql语句能否执行。其次察看代码,是否ExecuteNonQuery().
      

  21.   

    sqlInsertCommand1.CommandText="INSERT INTO (用户) VALUES('" + textBxo1.tText + "')"
      

  22.   

    sqlInsertCommand1.CommandText="INSERT INTO 用户 VALUES('"+textBox1.Text+"','"+textBox2.Text+"')"
      

  23.   

    sqlInsertCommand1.CommandText="INSERT INTO (用户) VALUES('" + textBox1.Text + "','" + textBox1.Text + "')";
    sqlInsertCommand1.ExecuteNonQuery();
    应该可以的吧。试试