Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Insert data into SQL Server
From Wiki
Summary: Insert data into SQL Server using a stored procedure and parameters
The SQL Server table:
- CREATE TABLE table1 (id int identity(1,1), myvalue int)
The SQL Server Stored procedure:
- CREATE procedure MyStoredProcedure
- (
- @MyParameter int
- )
- AS
- INSERT table1 (myvalue) VALUES (@MyParameter)
The ASP.NET commands to execute the strored procedure:
- ' Declarations
- Dim cn As New SqlConnection("Your connection string")
- Dim cmd As New SqlCommand("MyStoredProcedure", cn)
- ' Open the connection and add a parameter
- cn.Open()
- cmd.CommandType = CommandType.StoredProcedure
- cmd.Parameters.Add("@MyParameter", SqlDbType.Int).Value = 999
- ' Execute the query and close the connection
- cmd.ExecuteNonQuery()
- cn.Close()
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.