Link to home
Start Free TrialLog in
Avatar of Wanting2LearnMan
Wanting2LearnManFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Check if value exists in Access Database using c#

I wish to enter data into my access database table like so:

private OleDbConnection mycon;
string sDBPath = Application.StartupPath;
string sConnection = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\\MyAccessDB.mdb;Persist Security Info=False", sDBPath);

mycon = new OleDbConnection(sConnection);
OleDbCommand cmd = mycon.CreateCommand();
   cmd.CommandText = "insert into MyTable values('" + sID + "','" + sData1+ "','" + sData2+ "','" + sData3+ "','" + sData4+ "');";

cmd.ExecuteNonQuery();
 mycon.Close();

My question is how do I check if an entry already exists in the database row.  e.g. the first variable sID above?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of ErezMor
ErezMor
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial