Click here to Skip to main content
15,914,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hye..
I have a database call student which consists of all students information and also student id..
i have created a form that admin have to insert all the data about student..
then after admin click a save button,
i want to display all the information also with the student id(autonumber)..
i have try,but got an error..
this is my coding..
can anyone guide me..

C#
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=dbStd.mdb;");
OleDbCommand cmd = new OleDbCommand("SELECT StdId FROM Student WHERE StdId ='{0}'");
conn.Open();

OleDbDataReader dr = null;
dr = cmd.ExecuteReader();

while(dr.Read())
{
textBox1.Text = dr.GetString(0);
}


dr.Close();
conn.Close();
Posted
Updated 16-Dec-10 8:40am
v2
Comments
Abdul Quader Mamun 16-Dec-10 14:41pm    
Use pre tag.

Thank you for your question,

C#
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=dbStd.mdb;");
OleDbCommand cmd = new OleDbCommand("SELECT StdId FROM Student WHERE StdId =IdHere");
conn.Open();
OleDbDataReader dr = null;

cmd.Connection = conn; //add this line

dr = cmd.ExecuteReader();
while(dr.Read())
{
textBox1.Text = dr.GetString(0);
}

dr.Close();
conn.Close();



Thanks,
Mamun
 
Share this answer
 
v3
This may be me being very thick, but what is
WHERE StdId ='{0}'
supposed to achieve?
I know of no SQL syntax which includes this, where did you find it?


If you are going to save data and read it back immediately, you might want to consider using a Guid rather than an autonumber field - that way you are in control of the id and do not have to query the db to find out what value has been assigned.
 
Share this answer
 

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