Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

a few simple questions

Very basic one here.
How do i increment my value for image. So the second image is image02 then the third 03 etc. Thanks
I am using C# in visual studio
[168 byte] By [Visual n00b] at [2007-11-11 10:01:29]
# 1 Re: a few simple questions
int number = 1;
string filename = String.Format("image{0:00}.jpg", number);

number++;
filename = String.Format("image{0:00}.jpg", number);
Phil Weber at 2007-11-11 23:12:10 >
# 2 Re: a few simple questions
thanks phil, how would i go about updating a value in my users table. I am currently executing a scalar to return the current image no for that user, and then incrementing it before saving the new image. Now i need to record the new current image no in the table and know i need an update statement, however i have never used one so far thanks
Visual n00b at 2007-11-11 23:13:10 >
# 3 Re: a few simple questions
http://www.google.com/search?q=ado.net+update+table
Phil Weber at 2007-11-11 23:14:15 >
# 4 Re: a few simple questions
This is what i have come up with for an update statement. I am getting a syntax error when i execute the code. As i say i am not sure if this is the correct sql statement or not. ANy advice much appreciated thanks.

myConnection2.Open();

myCommand2.CommandText = "UPDATE [Users] SET [Image_no] VALUE(W8) WHERE User_Name = @W1";
myCommand2.Parameters.AddWithValue("@W8", Image_no);
myCommand2.Parameters.AddWithValue("@W1", CurrentUser);
myCommand2.ExecuteNonQuery();

myConnection2.Close();
Visual n00b at 2007-11-11 23:15:09 >
# 5 Re: a few simple questions
Try:

"UPDATE [Users] SET [Image_no] = @W8 WHERE User_Name = @W1"
Phil Weber at 2007-11-11 23:16:13 >
# 6 Re: a few simple questions
thanks
Visual n00b at 2007-11-11 23:17:19 >
# 7 Re: a few simple questions
You need to learn how to use the Visual Studio debugger. Set a breakpoint, for example, on the line:

int Image_no = Convert.ToInt32(myCommand.ExecuteScalar());

and confirm that you are indeed getting the desired value from the database. Then step through the code, examining variable values as you go, until you can find where it's not behaving as you expect it to.
Phil Weber at 2007-11-11 23:18:12 >
# 8 Re: a few simple questions
I have solved my problem thanks for your help.
Visual n00b at 2007-11-11 23:19:20 >