private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text != "")
{
string connsql = "Data Source=.;Initial Catalog=work;Integrated Security=True";
SqlConnection conn = new SqlConnection(connsql);
conn.Open();
string mysql = "select * from t1 where id='" + textBox1.Text + "' and pass='" + textBox2.Text + "'";
SqlCommand cmd = new SqlCommand(mysql, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string cmdtext="insert into t2 (id,name,xx) select id,name,xx from t1"; //这里不会
Form2 f2 = new Form2();
f2.Show();
}
conn.Close();
}
else
{
6 个解决方案
#1
语句格式你写得对的 就是的ID如果是自增长就不要插入了
insert into b(a, b, c) select d,e,f from b
insert into b(a, b, c) select d,e,f from b
#2
#3
嗯,
string cmdtext="insert into t2 (id,name,xx) select id,name,xx from t1";
那这句的前后的代码应该如何写?因为我前面打开了一次数据库,后面就不会写了,真心小白求教。
#4
SqlCommand cmdAdd = new SqlCommand(cmdtext, conn);
cmdAdd.ExecuteNoQuery();
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
cmdAdd.ExecuteNoQuery();
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
#5
string cmdtext="insert into t2 (id,name,xx) select id,name,xx from t1"; //當會員登錄成功之后,你把所有的會員信息都插入到登錄記錄表中了
//應該改為
string cmdtext="insert into t2(id,name,xx) select id,name,xx from t1 where t1.id='"+ textBox1.Text + "' and t1.pass='"+ textBox2.Text +"'";//這樣才把一個會員信息插入記錄表
SqlCommand sqlcmd = new SqlCommand(cmdtext, conn);
sqlcmd.ExecuteNoQuery();
#6
string cmdtext="insert into t2 (id,name,xx) select id,name,xx from t1";//當會員登錄成功之后,你把所有的會員信息都插入到登錄記錄表中了
//應該改為
string cmdtext="insert into t2(id,name,xx) select id,name,xx from t1 where t1.id='"+ textBox1.Text + "' and t1.pass='"+ textBox2.Text +"'";//這樣才把一個會員信息插入記錄表
SqlCommand sqlcmd = new SqlCommand(cmdtext, conn);
sqlcmd.ExecuteNoQuery();
#1
语句格式你写得对的 就是的ID如果是自增长就不要插入了
insert into b(a, b, c) select d,e,f from b
insert into b(a, b, c) select d,e,f from b
#2
#3
嗯,
string cmdtext="insert into t2 (id,name,xx) select id,name,xx from t1";
那这句的前后的代码应该如何写?因为我前面打开了一次数据库,后面就不会写了,真心小白求教。
#4
SqlCommand cmdAdd = new SqlCommand(cmdtext, conn);
cmdAdd.ExecuteNoQuery();
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
cmdAdd.ExecuteNoQuery();
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
#5
string cmdtext="insert into t2 (id,name,xx) select id,name,xx from t1"; //當會員登錄成功之后,你把所有的會員信息都插入到登錄記錄表中了
//應該改為
string cmdtext="insert into t2(id,name,xx) select id,name,xx from t1 where t1.id='"+ textBox1.Text + "' and t1.pass='"+ textBox2.Text +"'";//這樣才把一個會員信息插入記錄表
SqlCommand sqlcmd = new SqlCommand(cmdtext, conn);
sqlcmd.ExecuteNoQuery();
#6
string cmdtext="insert into t2 (id,name,xx) select id,name,xx from t1";//當會員登錄成功之后,你把所有的會員信息都插入到登錄記錄表中了
//應該改為
string cmdtext="insert into t2(id,name,xx) select id,name,xx from t1 where t1.id='"+ textBox1.Text + "' and t1.pass='"+ textBox2.Text +"'";//這樣才把一個會員信息插入記錄表
SqlCommand sqlcmd = new SqlCommand(cmdtext, conn);
sqlcmd.ExecuteNoQuery();