public static DataSet SelectSqlSrvRows(string myConnection, string mySelectQuery, string myTableName)
{
SqlConnection myConn = new SqlConnection(myConnection);
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
myDataAdapter.SelectCommand = new SqlCommand(mySelectQuery, myConn);
SqlCommandBuilder cb = new SqlCommandBuilder(myDataAdapter);
myConn.Open();
DataSet ds = new DataSet();
myDataAdapter.Fill(ds, myTableName);
//code to modify data in DataSet here
//Without the SqlCommandBuilder this line would fail
myDataAdapter.Update(ds, myTableName);
myConn.Close();
return ds;
}
------解决方案-------------------- 这只能解决有主键的数据表,对于没有主键的是不能解决的啊!