我正在用 asp.net 编写 Web 应用程序。我有一个输入表格。我想当客户端在插入之前单击保存按钮时,检查此数据是否在数据库中。我已经用后面的代码编写了它。但我想用 java 脚本来做这件事,因为当我使用页面刷新后面的代码时。这是我检查重复数据的 .net 代码:
SqlCommand commandrepeat1 = new SqlCommand("Select code from CmDet where code = " + txtcode.Text + " and company = " + DataBase.globalcompany.ToString() + " order by code desc");
commandrepeat1.Connection = objconnection;
objconnection.Close();
objconnection.Open();
SqlDataReader drmax1;
drmax1 = commandrepeat1.ExecuteReader();
drmax1.Read();
if (drmax1.HasRows)
{
MessageBox.Show("Duplicate data . try again!!! ");
txtcode.Focus();
objconnection.Close();
return;
}
objconnection.Close();
}
catch
{
objconnection.Close();
}