Answered by:
How do I clear the form after writing to sql db

Question
-
User-1641951882 posted
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connStr As String = ConfigurationManager.ConnectionStrings("PersonConnect").ToString() Dim myConnection As New SqlConnection(connStr) Dim insertStatement As String insertStatement = "INSERT INTO Person (Name, LastName, Address) VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')" Dim cmd As New System.Data.SqlClient.SqlCommand(insertStatement, myConnection) myConnection.Open() cmd.ExecuteNonQuery() myConnection.Close() End Sub The above code writes to sql db but does not clear the fields after writingMonday, April 4, 2011 10:57 PM
Answers
-
User1315229986 posted
If your page name is default.aspx, then after inserting the fields to DB just do
Response.Redirect("Default.aspx")
which will reload the page and all the entry fields will be cleared off
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 8, 2011 1:50 AM
All replies
-
User1831358492 posted
This post might help http://forums.asp.net/t/1015988.aspx/1
Monday, April 4, 2011 11:46 PM -
User3866881 posted
What do you mean by saying——
The above code writes to sql db but does not clear the fields after writing.
I think it can successfully do inserting, but what is :clear the fields?
Friday, April 8, 2011 1:30 AM -
User888410735 posted
Hi,
From your question what i understand is that after successfully inserting the values into the db you want the input fields to get cleared.if that is the case you can call the same page using response.Redirect("yourpage"). By doing this you can clear all the input fields in the page.If this is not you need please mention what is your exact requirement
Friday, April 8, 2011 1:40 AM -
User1315229986 posted
If your page name is default.aspx, then after inserting the fields to DB just do
Response.Redirect("Default.aspx")
which will reload the page and all the entry fields will be cleared off
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 8, 2011 1:50 AM