Thursday, March 22, 2012
OLEDB DATAREADER NOT WORKING
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;
> }
>
OLEDB DATAREADER NOT WORKING
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 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" wrote:
Quote:
Originally Posted by
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;
}
>
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 [C# MVP]" <pbromberg@.yahoo.yabbadabbadoo.comwrote in
message news:E76C3BF9-193D-4C3D-8923-39A4B1DEED05@.microsoft.com...
Quote:
Originally Posted by
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" wrote:
>
Quote:
Originally Posted by
>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;
> }
>>
OleDb FoxPro Problems!
I was using the code below to pull up records from an access database which worked fine, but I now want to do the same to a foxpro 7 database.
It connects to the foxpro dbase but after stepping through the code I found it crashes at
"dgPrevious.DataSource = cmdSelect.ExecuteReader"
the error is "Object reference not set to an instance of an object."
Dim con As OleDb.OleDbConnection
Dim cmdSelect As OleDb.OleDbCommand
Call OpenConnection() ' Own procedure
sqlquery = "SELECT Datereq, NetLogin, Title, Status, RequestId FROM " & tbname
cmdSelect = New OleDb.OleDbCommand(sqlquery, con)
dgPrevious.DataSource = cmdSelect.ExecuteReader
dgPrevious.DataBind()
Thanks
ChrisBy experience I find that if there is a problem with db connection it fails after code for connection but when you apply it.
Can you post the code for Call OpenConnection() ?
I suspect there is a problem here (perhaps).
OleDbException: Too many arguments.
I'm passing around 30 arguments to a stored procedure, and
I got the following error (see below).
It works fine if I narrow down to around 25 args. Is there
any workaround to bypass this exception, I need to pass 30
of them to my stored procedure. Thanks.
I'm using Framework 1.0.
--------
Too many arguments.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and where
it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Too
many arguments.
Source Error:
Line 663:
Line 664: 'execute SQL
Line 665: oCmd.ExecuteNonQuery()
Line 666:
Line 667: 'Catch exc As OleDbException
--------If you have any return parameters, they must be specified first. You should
declare any return parameters before you start adding input parameters. That
is commonly the reason for this error. Also, make sure that the order in
which you are adding your parameters match the order in the stored
procedure.
HTH,
Bill P.
"jn" <anonymous@.discussions.microsoft.com> wrote in message
news:001001c3aec9$13cedf10$a501280a@.phx.gbl...
> Hi,
> I'm passing around 30 arguments to a stored procedure, and
> I got the following error (see below).
> It works fine if I narrow down to around 25 args. Is there
> any workaround to bypass this exception, I need to pass 30
> of them to my stored procedure. Thanks.
> I'm using Framework 1.0.
> --------
> Too many arguments.
> Description: An unhandled exception occurred during the
> execution of the current web request. Please review the
> stack trace for more information about the error and where
> it originated in the code.
> Exception Details: System.Data.OleDb.OleDbException: Too
> many arguments.
> Source Error:
>
> Line 663:
> Line 664: 'execute SQL
> Line 665: oCmd.ExecuteNonQuery()
> Line 666:
> Line 667: 'Catch exc As OleDbException
> --------
arg, I found out it's Visual FoxPro problem (I'm using VFP
as the backend database), it just won't take more than 28
parameters. Thanks, Bill, for looking into my problem
though.
>--Original Message--
>If you have any return parameters, they must be specified
first. You should
>declare any return parameters before you start adding
input parameters. That
>is commonly the reason for this error. Also, make sure
that the order in
>which you are adding your parameters match the order in
the stored
>procedure.
>HTH,
>Bill P.
>
>"jn" <anonymous@.discussions.microsoft.com> wrote in
message
>news:001001c3aec9$13cedf10$a501280a@.phx.gbl...
>> Hi,
>>
>> I'm passing around 30 arguments to a stored procedure,
and
>> I got the following error (see below).
>> It works fine if I narrow down to around 25 args. Is
there
>> any workaround to bypass this exception, I need to pass
30
>> of them to my stored procedure. Thanks.
>> I'm using Framework 1.0.
>>
>> --------
>> Too many arguments.
>> Description: An unhandled exception occurred during the
>> execution of the current web request. Please review the
>> stack trace for more information about the error and
where
>> it originated in the code.
>>
>> Exception Details: System.Data.OleDb.OleDbException: Too
>> many arguments.
>>
>> Source Error:
>>
>>
>> Line 663:
>> Line 664: 'execute SQL
>> Line 665: oCmd.ExecuteNonQuery()
>> Line 666:
>> Line 667: 'Catch exc As OleDbException
>> --------
>>
>
>.
OleDbParameters
Hi everyone,
I'm having a little difficultywith parameterized values for a database. Below is my code:
[queries is an arry list of two strings: "flower" and "corner"]
SelectCmd = SELECT * FROM tblProducts WHERE(product_keywords LIKE'%@dotnet.itags.org.FLOWER%') OR (product_keywords LIKE'%@dotnet.itags.org.CORNER%')cmd =new OleDbCommand(SelectCmd);string paramValue;foreach (string xin queries) { paramValue ="@dotnet.itags.org." + x.ToUpper(); cmd.Parameters.Add(paramValue, OleDbType.VarChar); cmd.Parameters[paramValue].Value = x; } When I take off the parameters and the @dotnet.itags.org., I get 71 records returned but with the parameters no records are returned nor any error, furthermore I can't debug the statement.
Any input would be appreciated.
Thanks.
Eitan
It's the "...Like'%@.FLOWER%'... stuff that's the issue...
(untested...but try)... Like '%' + @.FLOWER + '%'.....
When I have done this I typically stick the % in the Value
So the Query would be
WHERE (Product_Keywords LIKE @.FLOWER )
And then the cmd.Parameters[paramValue].Value = "%" + x + "%";