这是我的代码。它不会更新表中的数据。我看不到任何错误。代码正在执行并向我显示“已成功更新”。
protected void btnUpdate_Click(object sender, EventArgs e)
{
string val = ddlCountry.SelectedValue;
Response.Write(val); // just to check that the value is changed or not.
string val2 = txtName.Text;
Response.Write(val2);
if (ddlCity.SelectedValue == "--Select--")
{
Response.Redirect("updateProfile.aspx");
lblCountry.Text = "Select your country";
}
else if(ddlYear.SelectedValue=="--Select--")
{
Response.Redirect("updateProfile.aspx");
lblCountry.Text = "Select Appropriate Experience";
}
else if (ddlMonth.SelectedValue == "--Select--")
{
Response.Redirect("updateProfile.aspx");
lblCountry.Text = "Select Appropriate Experience";
}
else if(ddlIndustry.SelectedValue=="--Select--")
{
Response.Redirect("updateProfile.aspx");
lblCountry.Text = "Select Your Current Industry";
}
else if(ddlFunction.SelectedValue=="--Select--")
{
Response.Redirect("updateProfile.aspx");
lblCountry.Text = "Select your functional Area";
}
else
{
string fName = Convert.ToString(Session["fname"]);
string updateQuery = "Update RegisterMaster set Name='" + txtName.Text + "',Nationality='" + ddlCountry.SelectedValue + "',CurrentLocation='" + ddlCity.SelectedValue + "',MobNumber='"+txtNumber.Text+"',Experience='"+ddlYear.SelectedValue+" "+ddlMonth.SelectedValue+"',CurrentIndustry='"+ddlIndustry.SelectedValue+"',FunctionalArea='"+ddlFunction.SelectedValue+"',KeySkills='"+txtSkills.Text+"',ResumeTitle='"+txtResTitle.Text+"',Resume='"+resFileUpload.ToString()+"' where Name='"+fName+"'";
int i = c1.ExecuteMyQuery(updateQuery);
if (i == 1)
{
lblUpdation.Text = "Successfully Updated.";
}
else
{
lblUpdation.Text = "Try Again";
}
}
}
它显示更新成功,但是当我检查数据库时,它没有更新。
updateProfile.aspx
是完成此编码的同一页面。如果这也很重要,它在一个框架集中。
实施
c1.ExecuteMyQuery(updateQuery);
public int ExecuteMyQuery(String sql)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = sql;
int i = cmd.ExecuteNonQuery();
con.Close();
return i;
}
这是什么????
哎呀!您的问题无法提交,因为:
您的帖子没有太多上下文来解释代码部分;请更清楚地解释您的情况。