System.Data.DataSet.Tables' is a 'property' but is used like a 'method'

R

Rich P

In VB.Net I do this:

1) Dim dr As DataRow = ds.Tables(0).Rows(i)

in VB.Net to C# converter it says this:

2) DataRow dr = ds.Tables(0).Rows(i);

but when I place 2) in my asp.net app (in C#) I get the following error:

System.Data.DataSet.Tables' is a 'property' but is used like a 'method

Here is the context:

protected void gridview1_SelectedIndexChanging(...)
{
int i = e.NewSelectedIndex;

conn1 = new
SqlConnection(ConfigurationManager.ConnectionStrings["myConnString"].Con
nectionString);
da = new SqlDataAdapter();
ds = new DataSet();
da.SelectCommand = conn1.CreateCommand();
da.SelectCommand.CommandText = "Select * From testTbl";
da.Fill(ds);

DataRow dr = ds.Tables(0).Rows(i); //<<--complains here
this.Label2.Text = dr["fName"].ToString();
this.Label3.Text = dr["lName"].ToString();
}

What do I need to do to fix this?


Rich
 
J

joecool1969

In VB.Net I do this:

1) Dim dr As DataRow = ds.Tables(0).Rows(i)

in VB.Net to C# converter it says this:

2) DataRow dr = ds.Tables(0).Rows(i);

but when I place 2) in my asp.net app (in C#) I get the following error:

System.Data.DataSet.Tables' is a 'property' but is used like a 'method

Here is the context:

protected void gridview1_SelectedIndexChanging(...)
{
  int i = e.NewSelectedIndex;

  conn1 = new
SqlConnection(ConfigurationManager.ConnectionStrings["myConnString"].Con
nectionString);
  da = new SqlDataAdapter();
  ds = new DataSet();
  da.SelectCommand = conn1.CreateCommand();
  da.SelectCommand.CommandText = "Select * From testTbl";
  da.Fill(ds);

  DataRow dr = ds.Tables(0).Rows(i); //<<--complains here
  this.Label2.Text = dr["fName"].ToString();
  this.Label3.Text = dr["lName"].ToString();

}

What do I need to do to fix this?  
I C# anytime you need to index a collection of objects, the syntax is
square brackets, not paranthesis, as in:

DataRow dr = ds.Tables[0].Rows;
 

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

Top