|
-
Jun 16th, 2007, 01:33 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Reader giving error on third read from database.
For the first two reads from the query, it seems like everything is fine. But for some reason the third read gives me an error no matter what I ask it to read from.
Error 1 Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?) C:\Inetpub\wwwroot\thisApp\userpage.aspx.cs 65 35 C:\...\thisApp\
This is the format of my code:
if (Label2.Text == usr)
{
if (Label3.Text == pss)
{
Label2.Text = reader["UserName"] + "<br />";
Label3.Text = reader["Password"] + "<br />";
Label4.Text = reader["Relation"];
//break; //exit out of the loop since user found
}
When I test it with this code it shows it up just fine:
//take the read data from the reader and display it
readDB_Lbl.Text = (String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}",
reader[0], reader[1], reader[2], reader[3], reader[4], reader[5], reader[6], reader[7], reader[8], reader[9], reader[10], reader[11], reader[12], reader[13], reader[14], reader[15], reader[16], reader[17], reader[18], reader[19], reader[20], reader[21], reader[22]));
I hope someone can give me a heads up, thank you in advance.
Also, I thought that in C# I could just return the lines to keep them short and that the semicolon would end a line and it wouldn't be a problem for lines to return but with this last bit of code even if I concatenate with a + it still errors out that it's needing to be closed. Why won't something like this work?
readDB_Lbl.Text = (String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, + {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, + {20}, {21}, {22}",
-
Jun 18th, 2007, 09:12 PM
#2
Thread Starter
Hyperactive Member
Re: Reader giving error on third read from database.
For the first part I found the answer. Since the database could contain a null in one of the columns, I need to cast .ToString()
Still not sure why the concatenation doesn't work for that last line of examples.
readDB_Lbl.Text = (String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, +
{20}, {21}, {22}",
How would you concatenate that line if it's not possible this way?
-
Jun 19th, 2007, 10:50 AM
#3
Re: Reader giving error on third read from database.
+ is string concatenation or variable addition.
Code:
readDB_Lbl.Text = (String.Format(@"{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7},
{20}, {21}, {22}",
Using the verbatim (@) should work for you.
-
Jun 20th, 2007, 12:30 AM
#4
Thread Starter
Hyperactive Member
Re: Reader giving error on third read from database.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|