Hi everyone,
I'm new to programming, and trying to learn and can't seem to find a clear-cut answer on how to insert text from a textbox into a database as a new record. I have a textbox and a button that when the button_click even is fired, that it will insert the data from the textbox as a new record. Any help will be greatly appreciated!!
If it's SQL Server you can do something like this (in C#)
SqlConnection conn = new SqlConnection("Server=<servername>;Database=<dbName>;Integrated Security=true");
conn.Open();
string sql = "Insert into.... the rest of your insert statement";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
Or you can modify that a bit and use a stored procedure if that suits your needs better. If you need to connect with a username/password just remove the integrated security part of the connection string and add the username/password.
Hope that helps.
|||i'm using Visual Basic
to perform an insert
when a button add is pressed
its surpose to insert the data from a textbox to the database
the data type of the tables column is char(4)
its similar to the top code but u have to add some other stuff do u know what they are
No comments:
Post a Comment