Hi folks,
I am working with ASP.NET 2.0 and am having a headache trying to check for an existing primary key in an Access database. I have a web form that will be used to add a new record of staff details. Currently there are several thousand members of staff that are stored in the database, each has a unique primary key entitled staff_id. This is simply a 4 digit number (for example, 2345), if I add a record with an existing staff ID it will post back an asp.net error. I am attempting (and rather badly) to write a script that will check for the existing field staff_id if the user enters an existing ID number in the web form textbox. This is what I have come up with so far but it simply throws back this error.
Error 2 Operator '==' cannot be applied to operands of type 'method group' and 'string' C:\Inetpub\wwwroot\CourseList\Admin\addStaff.aspx 23 12 C:\...\CourseList
I am working with C# and trying to convert a piece of
VB.Net code. I have done record checks before in classic asp and have never had a problem but now I am lost. This is the script I have written.
Code:
<script runat="server">
protected void bntClick_Click(object sender, EventArgs e)
{
Boolean ValidRecord;
string connStaff = ConfigurationSettings.AppSettings["ConnStaff"];
OleDbConnection conn = new OleDbConnection(connStaff);
conn.Open();
string sqlString = "SELECT COUNT(*) FROM staff WHERE staff_id = '" + txtstaffID.Text + "'";
OleDbCommand myCommand = new OleDbCommand(sqlString, conn);
object qryValue = myCommand.ExecuteScalar();
if(qryValue.ToString == txtstaffID.Text)
{
Label1.Text = "This is a duplicate record";
ValidRecord = false;
}
else
{
AccessDataSource3.Insert();
ValidRecord = true;
}
}
</script>
Any help with this would be greatly appreciated.