在使用ADO.NET的DataAdapterl来更新数据库遇到了点麻烦,望高手帮帮忙,解释一下为什么错了。
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace 数据库的更新
{
class Program
{
static void Main(string[] args)
{
SqlConnection con1 = new SqlConnection("server=local;Database=studdb;integrated security=SSPI");
try
{
con1.Open();
SqlDataAdapter adpate1 = new SqlDataAdapter("select * from student", con1);
DataSet ds1 = new DataSet();
adpate1.Fill(ds1, "student");
SqlCommandBuilder builder1 = new SqlCommandBuilder(adpate1);
DataColumn key = new DataColumn();
key = ds1.Tables["student"].Columns["学号"];
ds1.Tables["student"].PrimaryKey = key;
string ss = new string("20074054045");
DataRow findrow = ds1.Tables["student"].Rows.Find(ss);
if (findrow == null)
{
Console.WriteLine("{0} is not exits", ss);
DataRow row = ds1.Tables["student"].NewRow();
row["学号"] = ss;
ds1.Tables["student"].Rows.Add(row);
Console.WriteLine("Row {0} successfully added it into student", row);
}
else
{
Console.WriteLine("{0} find",ss);
}
}
catch (Exception e)
{
Console.WriteLine("输出错误:{0}", e.Message);
}
finally
{
if (con1 != null && con1.State != ConnectionState.Closed)
con1.Close();
}
}
}
}
错误 1 无法将类型“System.Data.DataColumn”隐式转换为“System.Data.DataColumn[]” E:\应用程序+例子\程序例子\c#\数据库的更新\数据库的更新\Program.cs 24 52 数据库的更新
错误 2 与“string.String(char*)”最匹配的重载方法具有一些无效参数 E:\应用程序+例子\程序例子\c#\数据库的更新\数据库的更新\Program.cs 25 29 数据库的更新
错误 3 参数“1”: 无法从“string”转换为“char*” E:\应用程序+例子\程序例子\c#\数据库的更新\数据库的更新\Program.cs 25 40 数据库的更新