在C#中连接数据库HR,查询其中的一张表,表名为变量,代码怎么写?
这是我写的代码,请问错在哪里了?stringTable=listBox1.SelectedItem.ToString();stringquery="select*into...
这是我写的代码,请问错在哪里了?
string Table = listBox1.SelectedItem.ToString();
string query = "select * into BulkCopyTable from @Table";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.Add(new SqlParameter("@Table", Table));
//SqlDataReader re = cmd.ExecuteReader();
//re.Close();
SqlDataAdapter ad = new SqlDataAdapter();
ad.SelectCommand = cmd;
DataSet ds = new DataSet();
SqlCommandBuilder bldr = new SqlCommandBuilder(ad);
ad.Fill(ds, "BulkCopyTable");
DataTable dt = new DataTable("BulkCopyTable");
BindingSource bs = new BindingSource(ds, "BulkCopyTable");
dataGridView1.DataSource = bs;
MessageBox.Show("操作成功!!!");
已解决,谢谢 展开
string Table = listBox1.SelectedItem.ToString();
string query = "select * into BulkCopyTable from @Table";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.Add(new SqlParameter("@Table", Table));
//SqlDataReader re = cmd.ExecuteReader();
//re.Close();
SqlDataAdapter ad = new SqlDataAdapter();
ad.SelectCommand = cmd;
DataSet ds = new DataSet();
SqlCommandBuilder bldr = new SqlCommandBuilder(ad);
ad.Fill(ds, "BulkCopyTable");
DataTable dt = new DataTable("BulkCopyTable");
BindingSource bs = new BindingSource(ds, "BulkCopyTable");
dataGridView1.DataSource = bs;
MessageBox.Show("操作成功!!!");
已解决,谢谢 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询