string str="update book set sortname='"+TextBox2.Text+"'where sortname='"+DropDownList1.SelectedValue.ToString()+"'";        SqlDataAdapter sda = new SqlDataAdapter();
        sda.UpdateCommand = new SqlCommand(str, con);

解决方案 »

  1.   

    +TextBox2.Text+"'where 
    --------
    sql中where前面少空格
      

  2.   

    你直接使用sqlcommand执行更新语句不行么?1 建立connection 2 绑定connection和sqlcommand以及上面提到的sql语句;3 打开connection4 调用sqlcommand的excutenonquery方法
      

  3.   

    直接用sqlcommand我知道,
    现在碰到用SqlDataAdapter的UpdateCommand想试试,竟然没反应
      

  4.   

        protected void Button1_Click(object sender, EventArgs e)
        {
            string str="update book set sortname='"+TextBox2.Text+"' where sortname='"+DropDownList1.SelectedValue.ToString()+"'";
            con.Open();
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.UpdateCommand = new SqlCommand(str, con);
            con.Close();
            ddlBind();
        }
    一个Dropdownlist,将选中的Text值编辑后再重新绑定
      

  5.   

    这样试试
    SqlConnection conn = new Connection(....);
    conn.open();
    SqlCommand cmd = new SqlCommand(conn,"你的sql语句");
    cmd.ExecuteNoQuery();
    conn.Close();
      

  6.   

    谢谢9楼,我知道SqlCommand 的用法
    想测试下SqlDataAdapter的UpdateCommand
      

  7.   

    sda.UpdateCommand = new SqlCommand(str, con);
    sda.Update("book");
    con.Close();
      

  8.   

    from msdn
    NET Framework 类库
    SqlDataAdapter.UpdateCommand 属性
    获取或设置一个 Transact-SQL 语句或存储过程,用于更新数据源中的记录。
    ------------
    从这里看出似乎这个只能更新数据源(比如dataset)而数据库是不能使用你的方法来进行更新
      

  9.   

    另外
    from msdn:
    在 Update 过程中使用的 SqlCommand,用于在数据库中更新对应于 DataSet 中已修改行的记录。
    ----------------
    也就是说这个updatecommand还不是如同我说的那样更新数据源(比如dataset),而是配合dataadapter自身的update方法来更新数据库
      

  10.   

    http://msdn2.microsoft.com/zh-cn/library/system.data.sqlclient.sqldataadapter.updatecommand(VS.80).aspx建议lz仔细看看msdn