Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 10, 2011 05:16 PM by Chen Yu - MSFT
Member
266 Points
287 Posts
Oct 06, 2011 03:51 PM|LINK
Ok i made it! :) but its not been added to my database i think lol.. i cant see it here this is my code and i tried also with @username @password Etc..
Didnt work :(
SqlCommand sqlcmd = new SqlCommand("INSERT INTO TABLE2 (username, pass, repass, email, reemail , name , age) VALUES ('" + usernametb.Text + "," + passtb.Text + "," + rpasstb.Text + "," + emailtb.Text + "," + remailtb.Text + "," + nametb.Text + "," + agetb.Text + "')"); sqlcmd.Parameters.AddWithValue("username", usernametb.Text); sqlcmd.Parameters.AddWithValue("password", passtb.Text); sqlcmd.Parameters.AddWithValue("repassword", rpasstb.Text); sqlcmd.Parameters.AddWithValue("email", email.Text); sqlcmd.Parameters.AddWithValue("reemail", remail.Text); sqlcmd.Parameters.AddWithValue("name", nametb.Text); sqlcmd.Parameters.AddWithValue("age", agetb.Text); Response.Redirect("~/AfterRegistreation.aspx");
Contributor
2981 Points
1350 Posts
Oct 06, 2011 04:16 PM|LINK
You need somthing like this in your code....
Dim command1 As New SqlCommand(sqlStmt, connection) connection.Open() command1.ExecuteNonQuery() connection.Close()
You also need to have a connection established. that is also covered in the links in my previous posts.
Oct 06, 2011 04:23 PM|LINK
i did made a connection with it didnt work
Oct 06, 2011 04:31 PM|LINK
Post the error.
Also take this line of code out until you get the page working...
Response.Redirect("~/AfterRegistreation.aspx");
Oct 06, 2011 04:34 PM|LINK
There is no error it just doesnt get registered i tried to look a bit online and im made some changes:
SqlConnection conn = new SqlConnection(); SqlDataAdapter da = new SqlDataAdapter(); SqlConnection sqlcon = new SqlConnection(@"Data Source=TZAHI-PC\SQLEXPRESS;Initial Catalog=RegisterDb;Integrated Security=True"); DataBinder ds = new DataBinder(); sqlcon.Open(); SqlCommand sqlcmd = new SqlCommand("INSERT INTO dbo.Table2 (username, pass, repass, email, reemail , name , age) VALUES ('" + usernametb.Text + "," + passtb.Text + "," + rpasstb.Text + "," + emailtb.Text + "," + remailtb.Text + "," + nametb.Text + "," + agetb.Text + "')"); sqlcmd.Parameters.AddWithValue("username", usernametb.Text); sqlcmd.Parameters.AddWithValue("password", passtb.Text); sqlcmd.Parameters.AddWithValue("repassword", rpasstb.Text); sqlcmd.Parameters.AddWithValue("email", emailtb.Text); sqlcmd.Parameters.AddWithValue("reemail", remailtb.Text); sqlcmd.Parameters.AddWithValue("name", nametb.Text); sqlcmd.Parameters.AddWithValue("age", agetb.Text); sqlcmd.ExecuteNonQuery();
Oct 06, 2011 04:43 PM|LINK
Put this...
Dim command1 As New SqlCommand(sqlcmd, sqlcon); connection.Open() ; command1.ExecuteNonQuery() ; connection.Close();
in place of this...
sqlcmd.ExecuteNonQuery();
Oct 06, 2011 04:44 PM|LINK
by the way, are you certain that you have a connection to the data source?
Can you query your DB and do you ahve write permissions on the database?
Oct 06, 2011 04:47 PM|LINK
i did it and it just says: "
Error 7 The type or namespace name 'Dim' could not be found (are you missing a using directive or an assembly reference?)"
Error 10 The name 'connection' does not exist in the current context
Oct 06, 2011 04:49 PM|LINK
ohh and how can i veify that i have a writing option>
Oct 06, 2011 05:04 PM|LINK
Sorry I missed this in your code change this....
connection.Open() ; command1.ExecuteNonQuery() ; connection.Close();
to this....
conn.Open() ; command1.ExecuteNonQuery() ; conn.Close();
tzahi2010
Member
266 Points
287 Posts
Re: Table With TextBoxes
Oct 06, 2011 03:51 PM|LINK
Ok i made it! :) but its not been added to my database i think lol.. i cant see it here this is my code
and i tried also with @username @password Etc..
Didnt work :(
SqlCommand sqlcmd = new SqlCommand("INSERT INTO TABLE2 (username, pass, repass, email, reemail , name , age) VALUES ('" + usernametb.Text + "," + passtb.Text + "," + rpasstb.Text + "," + emailtb.Text + "," + remailtb.Text + "," + nametb.Text + "," + agetb.Text + "')"); sqlcmd.Parameters.AddWithValue("username", usernametb.Text); sqlcmd.Parameters.AddWithValue("password", passtb.Text); sqlcmd.Parameters.AddWithValue("repassword", rpasstb.Text); sqlcmd.Parameters.AddWithValue("email", email.Text); sqlcmd.Parameters.AddWithValue("reemail", remail.Text); sqlcmd.Parameters.AddWithValue("name", nametb.Text); sqlcmd.Parameters.AddWithValue("age", agetb.Text); Response.Redirect("~/AfterRegistreation.aspx");march11
Contributor
2981 Points
1350 Posts
Re: Table With TextBoxes
Oct 06, 2011 04:16 PM|LINK
You need somthing like this in your code....
You also need to have a connection established. that is also covered in the links in my previous posts.
tzahi2010
Member
266 Points
287 Posts
Re: Table With TextBoxes
Oct 06, 2011 04:23 PM|LINK
i did made a connection with it
didnt work
march11
Contributor
2981 Points
1350 Posts
Re: Table With TextBoxes
Oct 06, 2011 04:31 PM|LINK
Post the error.
Also take this line of code out until you get the page working...
Response.Redirect("~/AfterRegistreation.aspx");
tzahi2010
Member
266 Points
287 Posts
Re: Table With TextBoxes
Oct 06, 2011 04:34 PM|LINK
There is no error
it just doesnt get registered i tried to look a bit online and im made some changes:
SqlConnection conn = new SqlConnection(); SqlDataAdapter da = new SqlDataAdapter(); SqlConnection sqlcon = new SqlConnection(@"Data Source=TZAHI-PC\SQLEXPRESS;Initial Catalog=RegisterDb;Integrated Security=True"); DataBinder ds = new DataBinder(); sqlcon.Open(); SqlCommand sqlcmd = new SqlCommand("INSERT INTO dbo.Table2 (username, pass, repass, email, reemail , name , age) VALUES ('" + usernametb.Text + "," + passtb.Text + "," + rpasstb.Text + "," + emailtb.Text + "," + remailtb.Text + "," + nametb.Text + "," + agetb.Text + "')"); sqlcmd.Parameters.AddWithValue("username", usernametb.Text); sqlcmd.Parameters.AddWithValue("password", passtb.Text); sqlcmd.Parameters.AddWithValue("repassword", rpasstb.Text); sqlcmd.Parameters.AddWithValue("email", emailtb.Text); sqlcmd.Parameters.AddWithValue("reemail", remailtb.Text); sqlcmd.Parameters.AddWithValue("name", nametb.Text); sqlcmd.Parameters.AddWithValue("age", agetb.Text); sqlcmd.ExecuteNonQuery();march11
Contributor
2981 Points
1350 Posts
Re: Table With TextBoxes
Oct 06, 2011 04:43 PM|LINK
Put this...
Dim command1 As New SqlCommand(sqlcmd, sqlcon);
connection.Open() ;
command1.ExecuteNonQuery() ;
connection.Close();
in place of this...
sqlcmd.ExecuteNonQuery();
march11
Contributor
2981 Points
1350 Posts
Re: Table With TextBoxes
Oct 06, 2011 04:44 PM|LINK
by the way, are you certain that you have a connection to the data source?
Can you query your DB and do you ahve write permissions on the database?
tzahi2010
Member
266 Points
287 Posts
Re: Table With TextBoxes
Oct 06, 2011 04:47 PM|LINK
i did it and it just says:
"
tzahi2010
Member
266 Points
287 Posts
Re: Table With TextBoxes
Oct 06, 2011 04:49 PM|LINK
ohh and how can i veify that i have a writing option>
march11
Contributor
2981 Points
1350 Posts
Re: Table With TextBoxes
Oct 06, 2011 05:04 PM|LINK
Sorry I missed this in your code change this....
connection.Open() ;
command1.ExecuteNonQuery() ;
connection.Close();
to this....
conn.Open() ;
command1.ExecuteNonQuery() ;
conn.Close();