I need some hints about sqlcommand
-
:confused: I'm trying to pass and retrieve data from textbox to sql server. I want to insert, delete, update, select from a table I write the following code. Can you help me for What I miss: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try sqlconn.Open() 'Insert command sqlstr = TextBox1.Text sqlcomm = New SqlCommand("insert into mytable name values sqlstr", sqlconn) TextBox2.Text = ("New Record inserted into Mytable table in pubs.") Catch MessageBox.Show("The Connection could not be opened!", "Error message !", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally sqlconn.Close() End Try End Sub Thanks
-
:confused: I'm trying to pass and retrieve data from textbox to sql server. I want to insert, delete, update, select from a table I write the following code. Can you help me for What I miss: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try sqlconn.Open() 'Insert command sqlstr = TextBox1.Text sqlcomm = New SqlCommand("insert into mytable name values sqlstr", sqlconn) TextBox2.Text = ("New Record inserted into Mytable table in pubs.") Catch MessageBox.Show("The Connection could not be opened!", "Error message !", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally sqlconn.Close() End Try End Sub Thanks
-
Add this line sqlcomm.ExecuteNonQuery() after this line sqlcomm = New SqlCommand("insert into mytable name values sqlstr", sqlconn)
-
Thanks for help: When I add sqlcomm.executenonquery() the code moves to catch and run the error message. Any Explanation about this please. Thanks
y_mmohd wrote:
the code moves to catch and run the error message. Any Explanation about this please.
Ask your application. It knows what the error was, but you don't ever find out.
Catch ex as SqlException
now, ex will contain the details of the error (ex.Message
will give you a reason) - it probably isn't to do with the connection, so your existing error message is misleading.
My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
-
:confused: I'm trying to pass and retrieve data from textbox to sql server. I want to insert, delete, update, select from a table I write the following code. Can you help me for What I miss: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try sqlconn.Open() 'Insert command sqlstr = TextBox1.Text sqlcomm = New SqlCommand("insert into mytable name values sqlstr", sqlconn) TextBox2.Text = ("New Record inserted into Mytable table in pubs.") Catch MessageBox.Show("The Connection could not be opened!", "Error message !", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally sqlconn.Close() End Try End Sub Thanks
Its Done, Thanks for Help :-D I need a to send string and retreive string to sql table using sql command. I write: sqlcomm = new sqlcomman (insert into mytable (name) values ('string'),sqlconn) Bu How can i do this using a textbox, I miss understand the syntax. Thanks