Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how we can check single row exist or not in database in c# ms access
Posted
Comments
An@nd Rajan10 20-Dec-13 4:11am    
what about solution 2

Write a query (Google is your friend[^]) and check the result.
 
Share this answer
 
try this code

C#
qry = "select * from department_master where dep_code='" + txt.Text + "'";
sql_cmd = new SqlCommand(qry, sql_con);
sql_con.Open();
sql_rs = sql_cmd.ExecuteReader();
if (sql_rs.Read())
{
    //exists
}
else
{
    //not exists
}
sql_rs.Close();
sql_con.Close();
 
Share this answer
 
v3
Hai
First u have use select data from database and fill into data table,and check row count,if it is above 1 then database have row,use where condition for select query then only u find exact data exit or not.
for examble

C#
OleDbConnection cn;
OleDbCommand cmd2;
cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" your dbpath herer ";Jet OLEDB:");
cn.Open();
OleDbDataAdapter objDA = new OleDbDataAdapter("select * from Users where UserId='007'", cn);
DataTable objDT = new DataTable();
objDA.Fill(objDT);
if ((objDT.Rows.Count == 1)) {
    // database have row
}

the above code for select exact data from table,here users is table,but u want database have data or not
try like this
C#
OleDbConnection cn;
OleDbCommand cmd2;
cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" your dbpath herer ";Jet OLEDB:");
cn.Open();
OleDbDataAdapter objDA = new OleDbDataAdapter("select * from Users", cn);
DataTable objDT = new DataTable();
objDA.Fill(objDT);
if ((objDT.Rows.Count == 1)) {
    // database have row
}



Regards
Aravind
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900