Thursday, March 22, 2012

OLEDB DATAREADER NOT WORKING

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;
}Take the completed srcCmd string, copy it into SQL queryAnalyzer, and execut
e
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" wrote:

> 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;
> }
>

0 comments:

Post a Comment