string cons = @"Data Source=GKJIANG-PC\SQLEXPRESS;Initial Catalog=学生管理;Integrated Security=True";
string sm = string.Format(comboBox1.SelectedItem.ToString() + "_学生信息");
//string sql = string.Format ( @"INSERT INTO {0}VALUES ( {1}, '{2}','{3}',{4},'{5}','{6}' )", sm, Convert.ToInt32(textBox3.Text), textBox4.Text, textBox5.Text, Convert.ToInt32(textBox6.Text), textBox7.Text, textBox8.Text);
string sql = " INSERT INTO" + sm + " VALUES (123132 ,'nani','n',23,'1989.12.1','ds')";
SqlConnection con = new SqlConnection(cons);
//SqlDataAdapter da = new SqlDataAdapter(sql, con);
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = sql;
MessageBox.Show("4");
try
{
con.Open();
int s=com.ExecuteNonQuery();
MessageBox.Show("数据添加成功");
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
|