473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SQL Datareader

front end: Visual Basic C# 2019;
back end: SQL Server 2017;

I am rather new to C# and could use some help. I am reading a SQL table using a SQL data reader. Here is the code

Expand|Select|Wrap|Line Numbers
  1. string strSQL = "select * from proddta.f4311 where pdan8='" + supplierNo + "' AND PDDRQJ>='" + jdeStart + "' AND PDDRQJ<='" + jdeEnd + "' order by pddrqj";
  2. SqlConnection con = new SqlConnection(SR_SupplierRatings.SQLTables.csJDE);
  3.             con.Open();
  4.             SqlCommand cmd = new SqlCommand(strSQL, con);
  5.             SqlDataReader dr = cmd.ExecuteReader();
  6.  
  7.             int myCount = 0;
  8.             try
  9.             {
  10.                 while (dr.Read())
  11.                 {
  12.                     if (dr("PDMCU") != 372)
  13.                     {
  14.                         myCount += 1;
  15.                     }
  16.                 }
  17.  
  18.                 con.Close();
  19.  
I am getting a compile error that states:

CS0149 Method name expected at this statement

Expand|Select|Wrap|Line Numbers
  1.  if (dr("PDMCU") != 372)
I cannot figure out why. Can someone help?

Thanks.
May 13 '19 #1
1 1369
zmbd
5,501 Expert Mod 4TB
Perhaps you should pull the information into a variable first and thin run the conditional...

Expand|Select|Wrap|Line Numbers
  1.   while (rdr.read())
  2.   {
  3.     //get the field - guessing it's an integer
  4.     Int myPDMCU = (int)rdr["PDMCU"]
  5.     if (myPDMCU != 372)
  6.     {
  7.       myCount ++;
  8.     }
  9.   }
May 15 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
6
by: Ravi | last post by:
Hi, I am not able to understand why a datareader needs a connection to the DB all the time. Here is what I tried. Sqlcommand cmd = ("select * from table1",con) // where con is the connection...
5
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
12
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. ...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
2
by: Andrei Pociu | last post by:
In a typical ASP .NET Web Application (website), I'm currently using a class where I declare some public static objects. For example there's the place where I initialize the SqlConnection. Also...
1
by: Brent | last post by:
I'm having a hard time wrapping my head around how to build a multi-dimensional array of n length out of a DataReader loop. Take this pseudo-code: ======================================= public...
7
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
7
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and...
3
by: Johnny Jörgensen | last post by:
I've got an error that I simply cannot locate: I've got a form in which I use a datareader object to read information from a db. After the read, I close the reader and I dispose of both the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.