我都是照这个网址里的操作的,为什么会出错呀?大家看下这个网址 http://www.cnblogs.com/herbert/archive/2010/08/31/1813824.html public partial class Form1 : Form
{
DataTable dataTable;
SqlDataAdapter da;
DataSet ds; public Form1()
{
InitializeComponent();
} public int UpdateByDataSet(DataSet ds, string strTblName, string strConnection)
{
try
{
SqlConnection conn = new SqlConnection(strConnection); SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand myCommand = new SqlCommand(("select * from " + strTblName), conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.Update(ds, strTblName);
return 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return -1;
}
} SqlConnection conn = new SqlConnection("Server=.;User Id=sa;Pwd=;DataBase=myDb_gzcf"); private void Form1_Load(object sender, EventArgs e)
{
conn.Open();
string select = "SELECT * FROM tb_stand";
da = new SqlDataAdapter(select, conn);
ds = new DataSet();
da.Fill(ds);
dataTable = ds.Tables[0];
ds.Tables[0].TableName = "tb_stand"; this.dataGridView1.DataSource = dataTable; } private void _save_Click(object sender, EventArgs e)
{
int flag;
flag = UpdateByDataSet(ds, "TestTable", conn);//这一句出错。错误1 Form1.UpdateByDataSet(System.Data.DataSet, string, string)”最匹配的重载方法具有一些无效参数, 错误 2 参数“3”: 无法从“System.Data.SqlClient.SqlConnection”转换为“string”
}
}
{
DataTable dataTable;
SqlDataAdapter da;
DataSet ds; public Form1()
{
InitializeComponent();
} public int UpdateByDataSet(DataSet ds, string strTblName, string strConnection)
{
try
{
SqlConnection conn = new SqlConnection(strConnection); SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand myCommand = new SqlCommand(("select * from " + strTblName), conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.Update(ds, strTblName);
return 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return -1;
}
} SqlConnection conn = new SqlConnection("Server=.;User Id=sa;Pwd=;DataBase=myDb_gzcf"); private void Form1_Load(object sender, EventArgs e)
{
conn.Open();
string select = "SELECT * FROM tb_stand";
da = new SqlDataAdapter(select, conn);
ds = new DataSet();
da.Fill(ds);
dataTable = ds.Tables[0];
ds.Tables[0].TableName = "tb_stand"; this.dataGridView1.DataSource = dataTable; } private void _save_Click(object sender, EventArgs e)
{
int flag;
flag = UpdateByDataSet(ds, "TestTable", conn);//这一句出错。错误1 Form1.UpdateByDataSet(System.Data.DataSet, string, string)”最匹配的重载方法具有一些无效参数, 错误 2 参数“3”: 无法从“System.Data.SqlClient.SqlConnection”转换为“string”
}
}
第三个参数string类型