Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class AccOpeningPage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
End Sub
Protected Sub btnsave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnsave.Click
Dim connetionString As String
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim sql As String
connetionString = "Data Source=abc-PC;Initial Catalog=aaadb;User ID=sa;Password=sa123"
cnn = New SqlConnection(connetionString)
cnn.Open()
MsgBox("Connection Open ! ")
sql = "insert into CUSTHEAD(CUSTID, BRCODE, SALUTEFLG, GENDER, CNAME, DOB, AGE, FORHNAME, ADD1, ACCTYPE, ACCNO) VALUES (@CUSTID,@BRCODE, @SALUTEFLG, @GENDER, @CNAME, @DOB, @AGE, @FORHNAME,@ ADD1, @ACCTYPE, @ACCNO)"
cmd = New SqlCommand(sql, cnn)
With cmd.Parameters
.AddWithValue("CUSTID", txtcustid.Text)
.AddWithValue("BRCODE", txtbrcode.Text)
.AddWithValue("SALUTEFLG", txtsalcode.Text)
.AddWithValue("GENDER", optmfj.SelectedItem.ToString())
.AddWithValue("CNAME", txtcname.Text)
.AddWithValue("DOB", txtdob.Text)
.AddWithValue("AGE", txtage.Text)
.AddWithValue("FORHNAME", txtforhname.Text)
.AddWithValue("ADD1", txtadd1.Text)
.AddWithValue("ACCTYPE", txtacctype.Text)
.AddWithValue("ACCNO", txtaccno.Text)
cmd.ExecuteNonQuery()
End With
cnn.Close()
End Sub
End Class
I get Error As
Must declare the scalar variable "@".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable