0
我有一个小问题把我带了一天,直到如今它不解决,我想保存未在数据库中存在的记录,如果用户输入已经存在的话,将不保存,但事情是它的工作原理不知何故后来我发现,当我试图验证第2行输入喜欢的用户名或电子邮件热潮相同的值!数据被插入,导致重复。如何解决这个问题?你能帮我吗?在这里感谢检查
是我的代码。
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblInternetAccount.Value = lblAccountNo.Text.ToString() + txtUsername.Text.ToString();
DataSet ds = new DataSet();
ds = (startWebService.getAllUsers());
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow drow in ds.Tables[0].Rows)
{
string username = drow["UserName"].ToString();
string acctNo = drow["AccountNumber"].ToString();
if (username != txtUsername.Text.ToString() || acctNo != lblAccountNo.Text.ToString())
{
startWebService.insertUser(lblAccountNo.Text.ToString(), txtUsername.Text.ToString(), txtPassword.Text.ToString(), txtUsername.Text.ToString(), cboQuestion.Text.ToString(), txtAnswer.Text.ToString(), lblInternetAccount.Value.ToString(), txtPassword.Text.ToString());
lblMessage.Text = "Record Updated!";
}
else
{
lblMessage.Text = "<br>Unable to create record because account number/email is already registered.Please login instead.<br><br>";
}
}
}
}
Web服务:
private DataSet GetDataSet(string strSPROC)
{
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = strSPROC;
conn.Open();
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
myDataAdapter.SelectCommand = cmd;
DataSet dsMT = new DataSet();
myDataAdapter.Fill(dsMT);
return dsMT;
conn.Close();
}
[WebMethod]
public void insertUser(string accountNo, string userName, string pAssword, string eMail, string secretQuestion, string secretAnswer,string onlineActNo,string acctkey)
{
Insert("ELMS_CREATEMEMBER", accountNo, userName, pAssword, eMail, secretQuestion, secretAnswer, onlineActNo,acctkey);
}
仍无法正常工作,记录已经存在,但系统再次保存它。 – Dhenn 2012-03-29 04:36:04
@Dhenn - 固定的代码,有一个小bug – Polity 2012-03-29 05:06:50
行会,我会跟踪它 – Dhenn 2012-03-29 05:31:16