Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 02, 2012 05:54 AM by Decker Dong - MSFT
Nov 29, 2012 03:57 PM|LINK
I changed the txtserachbox.text to SQL Ran so i know it has ran but the result still wont apper in the grid view
protected void btnsearch_Click(object sender, EventArgs e)
string conn_string = @"Provider=Microsoft.ACE.OLEDB.12.0;
Persist Security Info=False;";
using (OleDbConnection connection1 = new OleDbConnection(conn_string))
string query1 = "select * from song_tbl where sTitle = @searchQuary ";
OleDbCommand mySQLCommand1 = new OleDbCommand(query1, connection1);
myDataReader = mySQLCommand1.ExecuteReader();
if (myDataReader != null)
txtSearchbar.Text = "SQL Ran";
GridView1.DataSource = myDataReader;
txtSearchbar.Text = "No Matchfound";
Nov 29, 2012 04:04 PM|LINK
Nov 29, 2012 04:19 PM|LINK
Were will i put that code?....also imgetting a red line under .ExectueQuery();
Nov 29, 2012 04:33 PM|LINK
ExecuteNonQuery is used when no data is being returned, for example a delete, update or insert statement.
If data will be returned, use ExecuteReader. For example in your case where the select statement will return data. you already have this statement on the next line.
If only one cell is returned (ie. one 'peice' of data) you can use ExecuteScalar.
Nov 30, 2012 04:45 AM|LINK
First I'd like to say that I don't see anything obvious wrong with your codes……So please make sure that you GridView supports DataReader：
And you should notice that you cannot bind a DataReader directly to GridView, and you have to bind a DataTable to that.
If you wanna increase the speed, I think you can just try this by drag and drop a SqlDataReader onto the Web page, and then set its
DataSourceMode = DataReader.
Dec 01, 2012 11:33 PM|LINK
Decker Dong - MSFT
And you should notice that you cannot bind a DataReader directly to GridView
Yes, you can!
Dec 02, 2012 05:54 AM|LINK
Please check whether your DataReader can really read out data from db.
Sorry I've mixed the concepts……