Click here to Skip to main content
16,016,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
myConnect.open();
string myStringCommand = "SELECT ordinal, codeOfStu, fullName, ST.codeOfClass, CL.nameOfClass FROM Student ST, Class CL WHERE ST.codeOfClass = CL.codeOfClass AND ST.codeOfClass = @SelectedCodeOfClass";
OleDbCommand command = new OleDbCommand(myStringCommand, myConnect);
OleDbParameter myParameter = new OleDbParameter("@SelectedCodeOfClass", OleDbType.Integer);
myParameter.Value = SelectedCodeOfClass; // SelectedCodeOfClass is a parameter which is carried from main function.
myCommand.Parameters.Add(myParameter);
OleDbDataReader myReader = myCommand.ExecuteReader();
.
.
.

Now, I want not use "connect model" to access database anymore. I want use "disconnect model" to do that.
If I do like this:
OleDbDataAdapter adap=new OleDbDataAdapter("select * from tablename",con);
Dataset ds=new Dataset();
adap.fill(ds);

The Thing I receive is a datatable involve in all of the students. I don't want read all of the Student 's Information in database. I only want read students' Information according to class (codeOfClass) that they belong to
Posted

1 solution

Say the Code Of Class you want is 103010a
Change this line to

OleDbDataAdapter adap=new OleDbDataAdapter("select * from tablename",con);

OleDbDataAdapter adap=new OleDbDataAdapter("select * from tablename where CodeOfClass = '103010a'",con);

if its an int type, remove the 's
 
Share this answer
 
Comments
kid218 15-Oct-10 6:15am    
While the app is running, you don't know codeOfClass which I will choose, there are a lot of codeofclass in your table.

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