Tuesday, March 20, 2012

data reader problem

Hi, i dont know whats gone wrong! but all of a sudden it seems to be throwing an error, i have looked at my previous code and it matches exactly when it was working, here is the code below

int i = 0;for (i = 1; i <= 3; i++)

{

//This gets the stock ID from the textbox.

string stock_ID = ((TextBox)Panel1.FindControl("txtID" + i.ToString())).Text;

//This is the sql statement.

string sql ="SELECT [n_or_sh], [title], [cost_price], [selling_price] FROM tbl_stock WHERE stock_ID = " + stock_ID;

//This creates a sql command which executes the sql statement.

SqlCommand sqlCmd =newSqlCommand(sql, myConn);

myConn.Open();

//This is a reader for the results to go in.

SqlDataReader dr = sqlCmd.ExecuteReader();

//This reads the first result from the sqlReader

dr.Read();

//This sets the title label text to the value of the description column.

TextBox currentBox1 = (TextBox)Panel1.FindControl("txtDesc" + i);

string strtxtDesc = currentBox1.Text;

strtxtDesc = dr["title"].ToString();

};

myConn.Close();

i = 0;

the error its throwing is this

CS1519: Invalid token '(' in class, struct, or interface member declaration for the line myConn.Open()

does anybody have any idea how to solve this?

Jez

First thing is, you need to close the reader inside the loop, and for execute reader method passCommandBehavior.CloseConnection.Hopefully this fixes u r errors

|||

hi thanks for the tips, i have closed it inside the loop, but i dont get what you mean about the .closeconnection, could you please expalin more or give me an example in my code that i posted?

|||

http://msdn2.microsoft.com/en-us/library/aa326246(VS.71).aspx check this out

|||

Unmatched braces somewhere.

No comments:

Post a Comment