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
--
http://www.djberniev.beI think you query syntax is off. Try running it in query analyzer and fix
it.
"Bernie V" <bernd.vantyghem@.pandoradotbe> wrote in message
news:uXVuK8K8DHA.2924@.tk2msftngp13.phx.gbl...
> 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
>
> --
> http://www.djberniev.be
"Marina" <someone@.nospam.com> schreef in bericht
news:umi3Y$K8DHA.2064@.TK2MSFTNGP11.phx.gbl...
> 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
--
http://www.djberniev.be
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.
"Bernie V" <bernd.vantyghem@.pandoradotbe> wrote in message
news:#YfjfNL8DHA.1504@.TK2MSFTNGP12.phx.gbl...
> "Marina" <someone@.nospam.com> schreef in bericht
> news:umi3Y$K8DHA.2064@.TK2MSFTNGP11.phx.gbl...
> > 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
> --
> http://www.djberniev.be
"Marina" <someone@.nospam.com> schreef in bericht
news:umi3Y$K8DHA.2064@.TK2MSFTNGP11.phx.gbl...
> 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
Looks like you dont have a corresponding '('
Bernie V wrote:
> 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
--
Regards,
Dilip Krishnan
dilipkrish at msn. com
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment