C#中TextBox控件动态生成SQL表的问题,求教高手啊~~~
private void button1_Click(object sender, EventArgs e)
{
Conn con = new Conn(this.textBox1.Text, this.textBox2.Text, this.textBox3.Text, this.textBox4.Text);
SqlConnection sqlConnection = con.creatConn();
SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM Users WHERE UserName='" + this.textBox5.Text + "' and Password='" + this.textBox6.Text + "'", sqlConnection);
string t = cmd.ExecuteScalar().ToString();
if (t == "1")
{ MessageBox.Show("登陆成功","成功");
string user = this.textBox5.Text;
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
SqlCommand SCD = new SqlCommand("create table "+user+" (myid integer constraint pkeymyid primary key,myname char(50),myaddress char(255),mybalance float)", sqlConnection);
SCD.ExecuteNonQuery(); this.Hide();
SCD.Connection.Close();
}
前面不用看 关键是红字部分 数据库连接没有问题 如果用 "create table AAA"这样的语句建立个名字是AAA的表也没有问题
可是我想动态建一个表 表名是this.textBox5.Text的内容决定的 像上面那样写就要报错
是不是方法有问题??求教高手 卡了我2个多小时了~