string strUpdt = " UPDATE studentmessage SET unit = '"+ unit.Text + "' ,unitid = '" + unitid.Text + "' , studentno ='0 ' , birthyear = '" + birthyear.Text + "',studentsort='" + studentsort.Text + "',studentsource='" + studentsourcesort + "'  WHERE studentno = " + 0;
SqlCommand myCommand2 = new SqlCommand ( strUpdt , sqlConnection1 ) ;在WHere前加上空格看看。

解决方案 »

  1.   

    用数据集更新时候update()前先创建一个SqlCommandBuilder对象如SqlCommandBuilder cb= New SqlCommandBuilder(MyDataAdapter);
      

  2.   

    我看也许是因为你的SQL语句有问题吧。你最好用查询生成器生成这个UPDATE语句然后再做一些更改,这样就没有问题了。从你的SQL上看,可能是因为WHERE语句后的条件没有加上括号。
      

  3.   

    另外,看了一下你的下面的DataSet,也有问题。
    你的DataRow anyRow =dataSet61.studentmessage.Rows[0];命令会使anyRow成为dataSet61.studentmessage表的第一行的内容。
    改正如下:
    DataRow anyRow =dataSet61.studentmessage.NewRow();
    anyRow["unit"]= unit.Text;
    anyRow["unitid"]= unitid.Text;
    anyRow["报考号"]= 0;
    anyRow["birthyear"]= birthyear.Text;
    anyRow["studentsort"]= studentsort.Text ;
    anyRow["studentsourcesort"]= studentsourcesort.Text ;
    dataSet61.studentmessage.Rows.Add(anyRow);
    sqlDataAdapter1.Update(dataSet61);
      

  4.   

    为知道这些对你是否有帮助using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.Common;public class executingacommand
    {
      public static void Main()
      {
        executingacommand myexecutingacommand = new executingacommand();
        myexecutingacommand.Run();
      }  public void Run()
      {    SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;Trusted_Connection=yes;database=northwind");
        SqlCommand myCommand = new SqlCommand();
        SqlTransaction myTrans;    // Open the connection.
        myConnection.Open();    // Assign the connection property.
        myCommand.Connection  = myConnection;    // Begin the transaction.
        myTrans = myConnection.BeginTransaction();    // Assign transaction object for a pending local transaction
        myCommand.Transaction = myTrans;    try
        {
          // Restore database to near it's original condition so sample will work correctly.
          myCommand.CommandText = "DELETE FROM Region WHERE (RegionID = 100) OR (RegionID = 101)";
          myCommand.ExecuteNonQuery();      // Insert the first record.
          myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'MidWestern')";
          myCommand.ExecuteNonQuery();      // Insert the second record.
          myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'MidEastern')";
          myCommand.ExecuteNonQuery();      myTrans.Commit();
          Console.WriteLine("两个记录都已写入数据库!");
        }
        catch(Exception e)
        {
          myTrans.Rollback();
          Console.WriteLine(e.ToString());
          Console.WriteLine("两个记录都未写入数据库!");
        }
        finally
        {
          myConnection.Close();
        }
      }
    }
      

  5.   

    cath一个exception,把错误贴上来看看吧!