就得了,但是数据-添加新数据源-数据库-新建连接中的ConnectionString设置为
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\NWIND.mdb
系统就提醒我从索引0处就错了,Why?
运行已经成功了的,就是想试试VS的工具该怎么用
namespace RowOperationApp
{
class Program
{
static void Main(string[] args)
{
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\NWIND.mdb");
connection.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Employees", connection);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
DataSet dataset = new DataSet();
adapter.Fill(dataset,"Employees");
DataColumn[] keys = new DataColumn[2];
keys[0] = dataset.Tables["Employees"].Columns["FirstName"];
keys[1] = dataset.Tables["Employees"].Columns["LastName"];
dataset.Tables["Employees"].PrimaryKey = keys;
string[] name ={ "Feng", "Wang" };
DataRow findRow = dataset.Tables["Employees"].Rows.Find(name);
if (findRow == null)
{
Console.WriteLine("Row{0} {1}dont't exist,add it to Employees table", name[0], name[1]);
DataRow newRow = dataset.Tables["Employees"].NewRow();
newRow["FirstName"] = name[0];
newRow["LastName"] = name[1];
dataset.Tables["Employees"].Rows.Add(newRow);
Console.WriteLine("Row{0} {1}successfully added it into Employees table", name[0], name[1]);
}
else
{
Console.WriteLine("Row{0} {1}already exist in Wmployees table", name[0], name[1]);
}
adapter.Update(dataset, "Employees");
connection.Close();
}
}
}