K
Kevin R
I'm trying to update a sql database. It's modified Oledb code from an
example that did work with an access database. How can I tweak my code to
make it work?
Thanks in advance.
Kevin
======
Code error:
Line 24: Dim firstNameParam As New SqlParameter("@FirstName",
SqlDbType.VarChar, 10)
Error message detail:
C:\Begining ASP.NET 1.1\ch09\CommandExecute.aspx(24) : error BC30451: Name
'SqlDbType' is not declared.
My code:
'========================================================================================
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub btnRun_Click(sender As Object, e As EventArgs)
Dim ConnectionString As String =
"server=(local);database=northwind;trusted_connection=true"
Dim dbConnection As New sqlConnection(connectionString)
dbConnection.Open()
Dim commandString As String = "INSERT INTO Employees(FirstName,
LastName) " & _
"Values(@FirstName, @LastName)"
Dim dbCommand As New SqlCommand(commandString, dbConnection)
Dim firstNameParam As New SqlParameter("@FirstName",
SqlDbType.VarChar, 10)
firstNameParam.Value = txtFirstName.Text
dbCommand.Parameters.Add(firstNameParam)
Dim lastNameParam As New SqlParameter("@LastName",
SqlDbType.VarChar, 10)
LastNameParam.Value = txtLastName.Text
dbCommand.Parameters.Add(LastNameParam)
dbCommand.ExecuteNonQuery()
dbConnection.Close()
End Sub
example that did work with an access database. How can I tweak my code to
make it work?
Thanks in advance.
Kevin
======
Code error:
Line 24: Dim firstNameParam As New SqlParameter("@FirstName",
SqlDbType.VarChar, 10)
Error message detail:
C:\Begining ASP.NET 1.1\ch09\CommandExecute.aspx(24) : error BC30451: Name
'SqlDbType' is not declared.
My code:
'========================================================================================
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub btnRun_Click(sender As Object, e As EventArgs)
Dim ConnectionString As String =
"server=(local);database=northwind;trusted_connection=true"
Dim dbConnection As New sqlConnection(connectionString)
dbConnection.Open()
Dim commandString As String = "INSERT INTO Employees(FirstName,
LastName) " & _
"Values(@FirstName, @LastName)"
Dim dbCommand As New SqlCommand(commandString, dbConnection)
Dim firstNameParam As New SqlParameter("@FirstName",
SqlDbType.VarChar, 10)
firstNameParam.Value = txtFirstName.Text
dbCommand.Parameters.Add(firstNameParam)
Dim lastNameParam As New SqlParameter("@LastName",
SqlDbType.VarChar, 10)
LastNameParam.Value = txtLastName.Text
dbCommand.Parameters.Add(LastNameParam)
dbCommand.ExecuteNonQuery()
dbConnection.Close()
End Sub