Click here to Skip to main content
15,905,912 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
please see the code. data.Rows(index) is not working there is an error like:
can't be used like a method. Please help

string article_visit="0";
SqlConnection con=Database.GetConnection();

DataTable data=new DataTable();
SqlCommand sqlQuery=new SqlCommand("seelct * from category where article_allow = 1", con);
SqlDataAdapter dataAdapter=new SqlDataAdapter(sqlQuery);
//Dim dataAdapter As New OdbcDataAdapter(sqlQuery, connectionString)
dataAdapter.Fill(data);
//Dim index As Integer = 0
int index=0;
do
{
    article_visit="0";
    SqlCommand cmd=new SqlCommand("SELECT article_visit FROM article_list where cat_ID=" & data.Rows(index)("cat_ID") & " and article_status=1",con);
    dataAdapter=new SqlDataAdapter(cmd);
    DataTable data1=new DataTable();
    dataAdapter.Fill(data1);
    int index1=0;
    do
    {
        article_visit=int.Parse(data1.Rows(index1)("article_visit")) + article_visit;
        index1=index1+1;
    }while(index1<data1.Rows.Count);
    index=index+1;
}while(index<data.Rows.Count);


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 17-Jun-11 23:28pm
v2

1 solution

Replace the braces with square brackets: Arrays in C# are accessed with '[' and ']' not '(' and ')'
SqlCommand cmd=new SqlCommand("SELECT article_visit FROM article_list where cat_ID=" & data.Rows[index]["cat_ID"] & " and article_status=1",con);
 
Share this answer
 
Comments
rahul dev123 18-Jun-11 5:45am    
Still not working
rahul dev123 18-Jun-11 5:49am    
article_visit=int.Parse(data1.Rows[index1]["article_visit"]) + article_visit;
this line shown error like:
The best overloaded method match for 'int.Parse(string)' has some invalid arguments
OriginalGriff 18-Jun-11 5:53am    
So cast the cell value to a string...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900