trouble with DataReader

B

Bernie V

Hi group,

I'm trying to use a DataReader but I get an error.

This is my code:

private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection oCon = new SqlConnection("server=server;uid=id;" +
"pwd=pwd;database=database");
SqlCommand oCmd = new SqlCommand("SELECT nieuwsid, datum, titel FROM news
WHERE datum <= { fn CURDATE() })ORDER BY datum DESC",oCon);
oCon.Open();
oCmd.Connection=oCon;
SqlDataReader dr = oCmd.ExecuteReader();
oCmd.Dispose ();
oCon.Close();
oCon.Dispose();
}

I have an error at runtime on the line SqlDataReader dr =
oCmd.ExecuteReader();
The error is: Incorrect syntax near ')'.

With I simply delete the line with the error then I don't get an error, so I
think the error is in the line SqlDataReader dr = oCmd.ExecuteReader();

Can someone say what I do wrong ?

grz

Bernie V
 
B

Bernie V

Marina said:
I think you query syntax is off. Try running it in query analyzer and fix
it.

Hi Marina,

This was also my first opinion. But I changed the query to a simple select
query and I had the same problem.
The query like I use works in the query analyser.

grz

Bernie V
 
K

Kevin Spencer

The error message indicates a syntax problem with the query. I would suggest
either putting a breakpoint in, or recording the generated query somewhere
so that you can copy the generated query string and run it in Query Analyzer
to find out the problem with it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
B

Bernie V

Marina said:
I think you query syntax is off. Try running it in query analyzer and fix
it.

Marina,

I double cheked and you 're right !
There where to many ')' .

Thx !

grz

Bernie V
 
D

Dilip Krishnan

Looks like you dont have a corresponding '('

Bernie said:
Hi group,

I'm trying to use a DataReader but I get an error.

This is my code:

private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection oCon = new SqlConnection("server=server;uid=id;" +
"pwd=pwd;database=database");
SqlCommand oCmd = new SqlCommand("SELECT nieuwsid, datum, titel FROM news
WHERE datum <= { fn CURDATE() })ORDER BY datum DESC",oCon);
oCon.Open();
oCmd.Connection=oCon;
SqlDataReader dr = oCmd.ExecuteReader();
oCmd.Dispose ();
oCon.Close();
oCon.Dispose();
}

I have an error at runtime on the line SqlDataReader dr =
oCmd.ExecuteReader();
The error is: Incorrect syntax near ')'.

With I simply delete the line with the error then I don't get an error, so I
think the error is in the line SqlDataReader dr = oCmd.ExecuteReader();

Can someone say what I do wrong ?

grz

Bernie V
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top