Hi Good Guys,
I encounter another interesting problem due to my lack of C# knowledge. Please Help me.

I am trying to use DATAREADER to fill TEXTBOX controls on the FORM and it's not working because this coding generate error message:
sqlDR = sqlCmd.ExecuteReader(); <---- Error

Error message:
Error 1 Cannot convert method group 'ExecuteReader' to non-delegate type 'System.Data.SqlClient.SqlDataReader'. Did you intend to invoke the method?

Here are the coding:

private SqlConnection sqlconn;
 private SqlCommand sqlCmd;
 private SqlDataAdapter sqlDA;
 private SqlDataReader sqlDR;
 private DataSet DS;   


private void FDisplayCustomerDetails()
{
 /* display customer details */            
string strCustID = this.listBox1.SelectedValue.ToString();
string strSql = "Select * from Customers where CustomerId = '" + strCustID + "'";

try
   {
      sqlconn = new SqlConnection(connstr);
      sqlCmd = new SqlCommand(strSql, sqlconn);
      sqlconn.Open();
     sqlDR = sqlCmd.ExecuteReader();<---- Error 
     // display customer details from SQLDR and not Orders
     while (sqlDR.Read())
         {
           this.txtCustName.Text= sqlDR["CompanyName"].ToString();
           this.txtAddr.Text = sqlDR["Address"].ToString();
         }
     sqlDR.Close();
}  
Catch (Exception Ex)
    {
        MessageBox.Show(Ex.Message);
    }
}

Recommended Answers

All 2 Replies

Use sqlCmd.ExecuteReader() instead of sqlCmd.ExecuteReader

Hi Adatapost,
Thank you very much for sharing the information with me. I tried it out and it's working. You are awesome sharing information with me to help me.
This FORUM is awesome to have you .

Glad to meet you here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.