Marina K
asked on
Cannot convert sql query result in interger
I am trying to get the points value from the database. I am using an auto-increment ID so that the points i take are from the last log. Here is my code:
private void LevelTwoPartTwo_Load(objec t sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLoc alDB;Attac hDbFilenam e=C:\\User s\\Marina\ \Desktop\\ FaceNameGa me\\facena megame\\my gamedb.mdf ;Integrate d Security=True;Connect Timeout=30");
SqlCommand cmd = new SqlCommand("select Points from Userrecords where ID='MAX(ID) and Username='" + LoginInfo.UserID + "'", con);
con.Open();
point = Convert.ToInt32(cmd.Execut eScalar()) ;
//cmd.ExecuteNonQuery();
con.Close();
string[] files = Directory.GetFiles(@"C:\Us ers\Marina \Desktop\F aceNameGam e\images\L evel2\used ", "*.jpg", SearchOption.AllDirectorie s);
PhotoPicBx.Load(files[i]);
NameTxtBx.Focus();
Pointlbl.Text = point.ToString();
But it always throws exception that MAX('ID') cannot be converted to interger...what can i do?
(Sorry for my bad English, not my native language)
private void LevelTwoPartTwo_Load(objec
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLoc
SqlCommand cmd = new SqlCommand("select Points from Userrecords where ID='MAX(ID) and Username='" + LoginInfo.UserID + "'", con);
con.Open();
point = Convert.ToInt32(cmd.Execut
//cmd.ExecuteNonQuery();
con.Close();
string[] files = Directory.GetFiles(@"C:\Us
PhotoPicBx.Load(files[i]);
NameTxtBx.Focus();
Pointlbl.Text = point.ToString();
But it always throws exception that MAX('ID') cannot be converted to interger...what can i do?
(Sorry for my bad English, not my native language)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! This worked well...thank you very much
Open in new window