如何使用ASP.NET表单(文本框)传递karthik@domain.com和kars@domain.com?
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=new_db;" + "UID=root;" + "PASSWORD=password;" + "OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcCommand cmd = new OdbcCommand("UPDATE awm_create SET referral_email='karthik@domain.com' WHERE email='kars@domain.com'" , MyConnection);
MyConnection.Open();
cmd.ExecuteNonQuery();
答案 0 :(得分:0)
您必须在Web表单中添加两个asp.net文本框控件,并在回发时(使用IsPostBack标志),您可以从PageLoad事件中的文本框中提取电子邮件地址...即:
private void Page_Load()
{
if(Page.IsPostBack)
{
// add validation here for the text boxes if you need...
string refEmail= txtReferralEmail.Text.Trim();
string email = txtEmail.Text.Trim();
//then you can do something like this:
var sql = string.Format("UPDATE awm_create SET referral_email='{0}' WHERE email='{1}'", refEmail, email);
OdbcCommand cmd = new OdbcCommand(sql , MyConnection);
try{
MyConnection.Open();
cmd.ExecuteNonQuery();
}Catch(Exception e){
// log your exception or whatever you need to do
}
}
}
不要忘记你需要在你的aspx表单中添加两个文本框,名称为txtReferralEmail和txtEmail。
答案 1 :(得分:0)
抱歉,我得到了答案......
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=new_db;" + "UID=root;" + "PASSWORD=password;" + "OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcCommand cmd = new OdbcCommand("UPDATE awm_create SET referral_email=? WHERE email=?" , MyConnection);
cmd.Parameters.Add("@tb_refemail", OdbcType.VarChar, 255).Value = tb_refemail.Text.Trim();
cmd.Parameters.Add("@tb_email", OdbcType.VarChar, 255).Value = lblemail.Text;
MyConnection.Open();
cmd.ExecuteNonQuery();