By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

SQL Datareader

P: 1
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.
1 Week Ago #1
Share this Question
Share on Google+
1 Reply


zmbd
Expert Mod 5K+
P: 5,331
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.   }
1 Week Ago #2

Post your reply

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