未处理 System.Data.SqlClient.SqlException Message=数据库中已存在名为 'hy_Linshibiao' 的对象
private void listBox1_Click(object sender, EventArgs e)
{
string strTableName = this.listBox1.SelectedValue.ToString();
using(SqlConnection conn=new SqlConnection("server=localhost;database='"+strDatabase+"';uid=sa;pwd=chy19900909"))
{
错在这里,将string strSql;先声明,后使用,
string strSql= "select name 字段名, xusertype 类型编号, length 长度 into hy_Linshibiao from syscolumns where id=object_id('" + strTableName + "') ";
strSql += "select name 类型,xusertype 类型编号 into angel_Linshibiao from systypes where xusertype in (select xusertype from syscolumns where id=object_id('" + strTableName + "'))";
conn.Open();
SqlCommand cmd = new SqlCommand(strSql, conn);
cmd.ExecuteNonQuery();
conn.Close();
SqlDataAdapter da = new SqlDataAdapter("select 字段名,类型,长度 from hy_Linshibiao t,angel_Linshibiao b where t.类型编号=b.类型编号", conn);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView;
SqlCommand cmdnew = new SqlCommand("drop table hy_Linshibiao,angel_Linshibiao", conn);
conn.Open();
cmdnew.ExecuteNonQuery();
conn.Close();
}
}