| | |
How to check if an ID exist in database
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
Im doing an application n c# and using Ms Access 2003. i want to check whether a product id already exist in the database. Below is part of my code
C# Syntax (Toggle Plain Text)
string sql; OleDbCommand cmd; OleDbDataReader rdr; mDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" + Path.Combine(Application.StartupPath, "..\\..\\Company.mdb"); mDB.Open(); sql = "Select COUNT (*) ProductID FROM Product"; cmd = new OleDbCommand(sql, mDB); rdr = cmd.ExecuteReader(); if (txtProductID.Text == (string)rdr["ProductID"] ) { MessageBox.Show("ID exixst"); } else { return; }
•
•
Join Date: Oct 2009
Posts: 7
Reputation:
Solved Threads: 1
0
#2 Oct 22nd, 2009
Hi!
One possibility is, that you do an other sql-statement where you try to select the desired ProduktID:
I have not tested the code, but i think this should work!
Daniel
One possibility is, that you do an other sql-statement where you try to select the desired ProduktID:
C# Syntax (Toggle Plain Text)
string sqlString = "Select ProductID FROM Product where ProductID="+txtProductID.Text; OleDbCommand dbCmd = new OleDbCommand(sqlString, mDB); mDB.Open(); OleDbDataReader reader = dbCmd.ExecuteReader(); if (reader.Read()) { MessageBox.Show("ID exixst"); } else { // do something else here }
I have not tested the code, but i think this should work!
Daniel
![]() |
Similar Threads
- VB-MySQL Check if exist then insert (VB.NET)
- Check if user exists in db? (PHP)
- How to determine the availability of database file (Visual Basic 4 / 5 / 6)
- Check and Repair MySQL Database (MySQL)
- How to check my database (Visual Basic 4 / 5 / 6)
- Pascal database check (Pascal and Delphi)
- Doesn't check if username or email exits in database properly (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: Inserting data to a sql database table creating a new datarow instance
- Next Thread: C# Sql Connection for windows Application
| Thread Tools | Search this Thread |
.net 2008 access ado.net age amd array asp asp.net avatar backup basic bigbrother bluegene c# c++ check chips connection daniweb data database databaseconnection datagridview datetime development dos drawing economy energy enterprise enterprisesoftware file form forms gdi+ hardware http httpwebrequest ibm ibm.news images index insert intelibm linux list listbox medicine memory microsoft mysql news openoffice opensource operatingsystem oracle pc photoshop php post problem programming ps3 read recession record redhat remote remoting richtextbox russia saving search security server sql sql-server sqlite sqlserver sun supercomputer supercomputing survey table technology textbox trends ubuntu uk update vb vb.net visual visualstudio windows winforms working wpf x86






