public static bool IsInsertOK(string ID,string name,string sex)
{
string sql = "select * from table where id ='"+ID+"' and name ='"+name+"' and sex ='"+sex+"'";
....省略一段读数据库代码 //再加上 sqlCommand1这些东西定义你应该懂把
this.sqlCommand1.CommandText = sql;
System.Data.SqlClient.SqlDataReader reader;
this.sqlConnection1.Open();
reader = this.sqlCommand1.ExecuteReader();
this.sqlConnection1.Close();
bool ok = true;
if(reader.read())ok=false;
reader.close();
return ok;
}
ASP.NET 我不懂,不过我用ASP做过一个判断数据库里是否有相同内容的,以下是判断代码,希望对你有帮助。
<%Set rs1=Server.CreateObject("ADODB.Recordset")
sql1="select * from TYPE_INFO where company_id='"&company_id&"' and type_name='"&type_name&"' and status=1"
rs1.open sql1,oConn,1,3
if not rs1.eof then
response.Write("<script language='javascript'>")
response.Write("alert('类型名重复,请重新输入!');")
response.Write("window.history.go(-1);")
response.Write("</script>")
response.End
end if%>
判断数据库中是否有相同数据
自己写个验证的方法啊
public static bool IsInsertOK(string ID,string name,string sex)
{
string sql = "select * from table where id ='"+ID+"' and name ='"+name+"' and sex ='"+sex+"'";
....省略一段读数据库代码
bool ok = true;
if(reader.read())ok=false;
reader.close();
return ok;
}