asp+
This article will show you how to record your home on a SQL database in asp+.
Assuming you've mastered the basics of the database,
Ok
We make an Instance database demo table Sqladd, a field name (char)
We'll explain how to add data based on this database.
Now let's start coding.
First, we make a add.htm page (this is the page that submits the form)
<body>
<form method= "POST" action= "sql-add.aspx" >
<p>name: <input type= "text" name= "Name" size= "></p>
<p>
<input type= "Submit" value= "ADD" name= "B1" >
<input type= "reset" value= "Start-over" name= "B2" ></p>
</form>
</body>
In the second step, we will make the sql-add.aspx to save the data to the database page.
We will add the appropriate namespaces and connection strings (specify your server, username and password)
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>
<HTML>
<BODY>
<script language= "VB" runat= "Server" >
Sub Page_Load (Src as Object, E as EventArgs)
Dim MyConnection as SqlConnection
myconnection = new SqlConnection ("Server=localhost; Uid=sa; pwd=; Database=demo ")
Here we will declare mycommand as the SqlCommand variable to execute the INSERT statement
Dim MyCommand as SQLCommand
mycommand = new SQLCommand ("INSERT into Sqladd (name) VALUES ('" & Request.Form ("name") & ")",
MyConnection)
Finally, we open the database connection, execute the query, close the connection, the operation completed. The data is inserted into the database!
Myconnection.open ()
Mycommand.execute ()
Myconnection.close ()
Response.Write ("Record added successfully!") ")
End Sub
</script>
</BODY>
</HTML>
Below, show the complete source code.
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>
<HTML>
<title> Welcome to use chenyangasp Sample files </title>
<BODY>
<script language= "VB" runat= "Server" >
Sub Page_Load (Src as Object, E as EventArgs)
Dim MyConnection as SqlConnection
myconnection = new SqlConnection ("Server=localhost; Uid=sa; pwd=; Database=sean ")
Dim MyCommand as SQLCommand
mycommand = new SQLCommand ("INSERT into Sqladd (name) VALUES ('" & Request.Form ("name") & ")",
MyConnection)
Myconnection.open ()
Mycommand.execute ()
Myconnection.close ()
Response.Write ("Record added successfully!") ")
End Sub
</script> </HTML>