| | |
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: 12
Reputation:
Solved Threads: 2
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
Views: 1223 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for c#, check, database
.net 2008 access acquisition ado.net age amd array asp asp.net avatar backup basic bigbrother bluegene c# chat check chips connection daniweb data database datagridview development dos drawing dropdown ecommerce economy energy enterprise enterprisesoftware file form forms gdi+ hardware http ibm ibm.news images index intelibm javascript linux list listbox login math medicine memory microsoft mysql news openoffice opensource operatingsystem operator oracle pc photoshop php picturebox post problem programming ps3 read recession redhat remote remoting resource richtextbox russia saving search security server sql sql-server sqlite sqlserver sun supercomputer supercomputing survey table technology textbox trends ubuntu vb vb.net visualstudio webbrowser winforms working x86






