初写ADO.net,为什么更新不了,求指教。
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SqlConnection thisConnection = new SqlConnection(
@"Server=CHINESE-F1FA31E\MYSQLSERVER;User=CHINESE-F1FA31E;PWD=null;" + "Database=StudentsMIS");
SqlDataAdapter thisAdapter = new SqlDataAdapter (
"SELECT DepID,DepName FROM DepartmentName",thisConnection);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "DepartmentName");
Console.WriteLine("# rows before change:{0}",
thisDataSet.Tables["DepartmentName"].Rows.Count);
DataRow thisRow = thisDataSet.Tables["DepartmentName"].NewRow();
thisRow["DepID"] = "7";
thisRow["DepName"] = "德语学院";
thisDataSet.Tables["DepartmentName"].Rows.Add(thisRow);
Console.WriteLine("# rows after change:{0}",
thisDataSet.Tables["DepartmentName"].Rows.Count);
thisAdapter.Update(thisDataSet, "DepartmentName");
thisConnection.Close();
Console.WriteLine("Program finished, press Enter/Return to continue:");
Console.ReadLine();
}
}
}
database
------解决方案--------------------string connstring = @"server=server;database=s2;uid=uid;pwd=psw";
using (SqlConnection thisConnection = new SqlConnection(connstring))
{
SqlDataAd