OLEDB DATAREADER NOT WORKING

J

John Chapman

Hello, I am using the code down below and I keep receiving the error: No
value given for one or more required parameters.

What am I doing wrong?

protected void dgCustomerSearch_Sort(object sender, EventArgs e)
{
string strCustomerSearchQry;
string strSortExp = dgCustomerSearch.SortExpression.ToString();
strCustomerSearchQry = txtSearchCustomer.Text;
lblCustSrchNotValid.Visible = false;

string srcConString = "Provider=Microsoft.Jet.OleDb.4.0;Data
Source=" + MapPath("cpaneldb.mdb");
OleDbConnection objConString = new OleDbConnection(srcConString);
string srcCmd = "SELECT * FROM tbl_customers WHERE
((tbl_customers.[ID] LIKE '%" + strCustomerSearchQry + "%') OR
(tbl_customers.[LASTNAME] LIKE '%" + strCustomerSearchQry + "%')) ORDER BY
tbl_customers.[" + strSortExp + "]";
objConString.Open();
OleDbCommand objCmd = new OleDbCommand(srcCmd, objConString);
OleDbDataReader objRdr;
objRdr = objCmd.ExecuteReader();
dgCustomerSearch.DataSource = objRdr;
dgCustomerSearch.DataBind();
objRdr.Close();
objConString.Close();
dgCustomerSearch.Visible = true;
}
 
G

Guest

Take the completed srcCmd string, copy it into SQL queryAnalyzer, and execute
it.
You will see what is wrong.
Peter
 
J

John Chapman

Thank you, I actually found that the issue was that the way I was
retrieving the sort expression returned nothing. So it was looking to sort
by a blank field.

Peter Bromberg said:
Take the completed srcCmd string, copy it into SQL queryAnalyzer, and
execute
it.
You will see what is wrong.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




John Chapman said:
Hello, I am using the code down below and I keep receiving the error: No
value given for one or more required parameters.

What am I doing wrong?

protected void dgCustomerSearch_Sort(object sender, EventArgs e)
{
string strCustomerSearchQry;
string strSortExp = dgCustomerSearch.SortExpression.ToString();
strCustomerSearchQry = txtSearchCustomer.Text;
lblCustSrchNotValid.Visible = false;

string srcConString = "Provider=Microsoft.Jet.OleDb.4.0;Data
Source=" + MapPath("cpaneldb.mdb");
OleDbConnection objConString = new OleDbConnection(srcConString);
string srcCmd = "SELECT * FROM tbl_customers WHERE
((tbl_customers.[ID] LIKE '%" + strCustomerSearchQry + "%') OR
(tbl_customers.[LASTNAME] LIKE '%" + strCustomerSearchQry + "%')) ORDER
BY
tbl_customers.[" + strSortExp + "]";
objConString.Open();
OleDbCommand objCmd = new OleDbCommand(srcCmd, objConString);
OleDbDataReader objRdr;
objRdr = objCmd.ExecuteReader();
dgCustomerSearch.DataSource = objRdr;
dgCustomerSearch.DataBind();
objRdr.Close();
objConString.Close();
dgCustomerSearch.Visible = true;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top