asp.net 的页面上填写的内容同时写入数据库的两张表
要求点击"提交"按钮把信息写入到两张表中比如:username写入A表,address写入B表....
要求点击"提交"按钮把信息写入到两张表中
比如:username写入A表,address写入B表. 展开
比如:username写入A表,address写入B表. 展开
2个回答
展开全部
那就在提交事件里执行2次SQL嘛
void Button1_Click(object sender, System.EventArgs e)
{
string tmp = username.Text.Replace("'","''");
string sql = "insert into A (colA) values('" + tmp + "')";
SqlConnection con = new SqlConnection("连接字符串");
con.Open();
SqlCommand com = new SqlCommand(sql,con);
com.ExecuteNone(sql);
tmp = address.Text.Replace("'","''");
sql = "insert into B (colB) values('" + tmp + "')";
com.ExecuteNone(sql);
}
void Button1_Click(object sender, System.EventArgs e)
{
string tmp = username.Text.Replace("'","''");
string sql = "insert into A (colA) values('" + tmp + "')";
SqlConnection con = new SqlConnection("连接字符串");
con.Open();
SqlCommand com = new SqlCommand(sql,con);
com.ExecuteNone(sql);
tmp = address.Text.Replace("'","''");
sql = "insert into B (colB) values('" + tmp + "')";
com.ExecuteNone(sql);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询