這是我的代碼。我有3個表名爲我可以將數據插入3個不同表中的列嗎?
帳戶,WaterDB,ElectricDB和GasDB。
- 在下面的代碼中,我將信息插入到acounts表中。
在我的帳戶WaterDB,ElectricDB和GasDB中,我有一個名爲username的專欄。
我是否可以將用戶名插入其他表的「用戶名」列?
代碼,我插入信息到我的賬表:
protected void registerBtn_Click1(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["userDatabaseConnectionString1"].ConnectionString);
conn.Open();
string insertQuery = "insert into accounts (username,email,password,postalcode,role) values (@Uname ,@email ,@pswd ,@pstlc,@role)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@Uname", registerUsernameTB.Text);
com.Parameters.AddWithValue("@email", registerEmailTB.Text);
com.Parameters.AddWithValue("@pswd", registerUserPswdTB.Text);
com.Parameters.AddWithValue("@pstlc", postalCodeTB.Text);
com.Parameters.AddWithValue("@role", role.Text);
com.ExecuteNonQuery();
Response.Redirect("Loginx.aspx");
Response.Write("Registration is successful");
conn.Close();
}
你在「賬戶」表格以外只有單列嗎? – Lali
不,我有其他列,但唯一的類似列是4個數據庫中的'用戶名' – user3441128
您的意思是* 3表*或* 3數據庫*中的(類似)表? – user2864740