Hi there,
Please take a look at the source code and tell me whats wrong?
Imports System.Data
Imports System.Data.SqlClient
Partial Class Test
Inherits System.Web.UI.Page
Const conString As String = "Data Source=.;Initial
Catalog=Northwind;Integrated Security=True"
Public Function MyInsertMethod() As Integer
Dim con As New SqlConnection(conString)
Dim insertString As String = "Exec usp_InsertTest
@CustomerID,@FirstName,@LastName"
Dim cmd As New SqlCommand(insertString, con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call MyInsertMethod()
End Sub
End Class
I created a table Test with CustomerID nvarchar(50),FirstName
nchar(10),@LastName nchar(10)
Along with the usp_InsertTest
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_InsertTest]
(@CustomerID nvarchar(50),@FirstName nchar(10),@LastName nchar(10))
AS
Insert into dbo.Test
(CustomerID,FirstName,LastName)
Values
(@CustomerID,@FirstName,@LastName)
Return
When I click submit I'm getting an error that says
"Must Declare the Scalar Variable"
Ho can I fix this
Thanks
Oded Dror 2 6591
Hi,
If your SqlCommand object (cmd in this case) has some parameter in its
CommandText then you have to add those parameters to your SqlCommand
object's Parameters collection that is (something like):
cmd.Parameters.Add("@CustomerID", "SomeCustID")
cmd.Parameters.Add("@FirstName", "John")
cmd.Parameters.Add("@LastName", "DOE")
Check MSDN on SqlParameter for more information.
Regards.
"Oded Dror" <od******@cox.net> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl... Hi there,
Please take a look at the source code and tell me whats wrong?
Imports System.Data Imports System.Data.SqlClient Partial Class Test Inherits System.Web.UI.Page Const conString As String = "Data Source=.;Initial Catalog=Northwind;Integrated Security=True" Public Function MyInsertMethod() As Integer Dim con As New SqlConnection(conString) Dim insertString As String = "Exec usp_InsertTest @CustomerID,@FirstName,@LastName" Dim cmd As New SqlCommand(insertString, con) con.Open() cmd.ExecuteNonQuery() con.Close() End Function Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Call MyInsertMethod() End Sub End Class
I created a table Test with CustomerID nvarchar(50),FirstName nchar(10),@LastName nchar(10)
Along with the usp_InsertTest
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[usp_InsertTest] (@CustomerID nvarchar(50),@FirstName nchar(10),@LastName nchar(10)) AS Insert into dbo.Test (CustomerID,FirstName,LastName) Values (@CustomerID,@FirstName,@LastName) Return
When I click submit I'm getting an error that says "Must Declare the Scalar Variable"
Ho can I fix this
Thanks Oded Dror
I chenged the connection string to sqlDatasource1
This is sql client connection that I created
And now this is the error message that I'm getting
Format of the initialization string does not conform to specification
starting at index 0
How to fix that!
Thanks,
Oded Dror
"Oded Dror" <od******@cox.net> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl... Hi there,
Please take a look at the source code and tell me whats wrong?
Imports System.Data Imports System.Data.SqlClient Partial Class Test Inherits System.Web.UI.Page Const conString As String = "Data Source=.;Initial Catalog=Northwind;Integrated Security=True" Public Function MyInsertMethod() As Integer Dim con As New SqlConnection(conString) Dim insertString As String = "Exec usp_InsertTest @CustomerID,@FirstName,@LastName" Dim cmd As New SqlCommand(insertString, con) con.Open() cmd.ExecuteNonQuery() con.Close() End Function Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Call MyInsertMethod() End Sub End Class
I created a table Test with CustomerID nvarchar(50),FirstName nchar(10),@LastName nchar(10)
Along with the usp_InsertTest
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[usp_InsertTest] (@CustomerID nvarchar(50),@FirstName nchar(10),@LastName nchar(10)) AS Insert into dbo.Test (CustomerID,FirstName,LastName) Values (@CustomerID,@FirstName,@LastName) Return
When I click submit I'm getting an error that says "Must Declare the Scalar Variable"
Ho can I fix this
Thanks Oded Dror
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jiggaz |
last post by:
Hi,
Look my stored procedure :
__________________
ALTER PROCEDURE dbo.CreateAccount
@Nickname varchar(30),
@Password varchar(15),
@Email varchar(50),
@Date datetime,
|
by: Ken Adeniji |
last post by:
Must declare the scalar variable '@FirstName'
ContactGridViewWebForm.aspx
<aspqlDataSource
RunAt="server"
ID="SqlDataSourceContact"
...
|
by: AndrewD |
last post by:
when the following SELECT is executed via A cursor to SQL 2005 it works
SELECT * FROM LCTRY
WHERE LANGUAGE = 'EN' AND CTRY_CODE = :CTRY
BUT
SELECT * FROM LCTRY
WHERE CTRY_CODE = :CTRY...
|
by: Rama Jayapal |
last post by:
the following is my code
can anybody rectify my problem that i get when running my application
"Must declare scalar variable @ID"
<asp:GridView ID="GridView1" DataKeyNames="ID" runat="server"...
|
by: roamnet |
last post by:
hi
i created database file with .mdf extention ,sql server as a source
and use grid view to display data
there're no problem in data retrieve and display,but i want to edit it
or insert new...
|
by: saravana784 |
last post by:
USE
GO
/****** Object: StoredProcedure . Script Date: 06/09/2007 20:15:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
|
by: =?Utf-8?B?V0pC?= |
last post by:
I'm trying to understand the full interaction between controls on a formview
that are bound to a SQLDataSource and the binding of the data using ASP.Net
2.0. When I set ConflictDetection to...
|
by: Mark |
last post by:
I am really struggling with this, trying to understand why it doesn't work.
I've simplified the code down to the essentials. The GridView displays in
ReadOnly mode just fine, Clicking the "edit"...
|
by: Tony M |
last post by:
vs 2005 - vb .net - web forms - xp pro
Can't figure out why I keep getting the error Must declare the scalar
variable "@CheckUser".
The error happens on SqlDA.Fill(SqlDS). Just trying to make...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |