Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 16, 2013 10:07 PM by Harpreet09
0 Points
2 Posts
Feb 16, 2013 04:30 PM|LINK
Hello. I have been having problems for some time,
protected void Button6_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=localhost;" + "Initial Catalog=ASPProject; Integrated Security=SSPI");
conn.Open(); string mySQL;
mySQL = " INSERT into JobApply (Apply_Name, Apply_User,Apply_Job) VALUES ('"+ txtName.Text.Trim() + "','" + txtUser.Text.Trim() + "','" + txtApply.Text.Trim() + "')"; SqlCommand cmd = new SqlCommand(mySQL, conn); cmd.ExecuteNonQuery(); conn.Close(); }
This is my codes, I want to update this into my database however its not working and I can't find any build errors. Would really appreciate the help!!!
Star
13411 Points
2535 Posts
Feb 16, 2013 09:59 PM|LINK
Put a breakpoint on the
SqlCommand cmd = new SqlCommand(mySQL, conn);
Look at the value of mySQL
Copy that string into your database management tool (SQL Server Management Studio or whatever) and execute it. What happens?
(PS - You should study this carefully http://xkcd.com/327/ and make sure you understand what it is telling you. If you don't understand why it is relevent to you then stop work and start researching at http://en.wikipedia.org/wiki/SQL_injection)
Member
168 Points
41 Posts
Feb 16, 2013 10:07 PM|LINK
Try to put try catch in the code and find out the exception.
May be ur sqlconnection string is not correct.Otherwise, code looks ok to me.
cherylteo93
0 Points
2 Posts
Facing problems updating database.
Feb 16, 2013 04:30 PM|LINK
Hello. I have been having problems for some time,
protected void Button6_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=localhost;" +
"Initial Catalog=ASPProject; Integrated Security=SSPI");
conn.Open();
string mySQL;
mySQL = " INSERT into JobApply (Apply_Name, Apply_User,Apply_Job) VALUES ('"+ txtName.Text.Trim() + "','" + txtUser.Text.Trim() + "','" + txtApply.Text.Trim() + "')";
SqlCommand cmd = new SqlCommand(mySQL, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
This is my codes, I want to update this into my database however its not working and I can't find any build errors. Would really appreciate the help!!!
Paul Linton
Star
13411 Points
2535 Posts
Re: Facing problems updating database.
Feb 16, 2013 09:59 PM|LINK
Put a breakpoint on the
SqlCommand cmd = new SqlCommand(mySQL, conn);
Look at the value of mySQL
Copy that string into your database management tool (SQL Server Management Studio or whatever) and execute it. What happens?
(PS - You should study this carefully http://xkcd.com/327/ and make sure you understand what it is telling you. If you don't understand why it is relevent to you then stop work and start researching at http://en.wikipedia.org/wiki/SQL_injection)
Harpreet09
Member
168 Points
41 Posts
Re: Facing problems updating database.
Feb 16, 2013 10:07 PM|LINK
Try to put try catch in the code and find out the exception.
May be ur sqlconnection string is not correct.Otherwise, code looks ok to me.
Regards
Harpreet Singh