Failed to convert parameter value from a String to
Hi All
I am just a novice in C# and got stuck on one point. I am using Javascript to validate my input in textbox1, The input has to be in numeric only. regular expression used in javascript is RE = new RegExp("[0-9]"). But when i am entering alphanumeric value, i am getting error as Failed to convert parameter value from a String to a Int32.
I am buiding a login page using duwamish architecture.
my access.cs code is:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace DataAccess
{
public class Access
{
public bool LoginDetails(string struserid, string strpassword)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= C:\Documents and Settings\10082\" +
@"My Documents\user.mdb";
OleDbCommand cmd = new OleDbCommand("select Name,Department,Vertical,Location from user1 where userid=@userid and password=@password", conn);
cmd.Parameters.Add("@userid", OleDbType.Integer, 10);
cmd.Parameters["@userid"].Value = struserid;
cmd.Parameters.Add("@password", OleDbType.WChar, 50);
cmd.Parameters["@password"].Value = strpassword;
conn.Open();
OleDbDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
return true;
else
return false;
//OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
//DataSet ds = new DataSet();
//ad.Fill(ds, "user1");
// Verify whether the user is existing from the returned dataset.
// In case no user details exist with the provided credentials,
//return false. Otherwise true.
}
public DataSet GetDetails(string struserid)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= C:\Documents and Settings\10082\" +
@"My Documents\user.mdb";
string strSelectQuery = "select Name,Department,Vertical,Location from user1 where userid=@userid";
OleDbCommand cmd1 = new OleDbCommand(strSelectQuery, conn);
cmd1.Parameters.Add("@userid", OleDbType.Integer, 10);
cmd1.Parameters["@userid"].Value = struserid;
//cmd.Parameters.Add("@password", OleDbType.WChar, 50);
//cmd.Parameters["@password"].Value = strpassword;
conn.Open();
OleDbDataAdapter ad = new OleDbDataAdapter(cmd1);
DataSet ds = new DataSet();
ad.Fill(ds);
return ds;
}
}
}
Please help....
|