473,698 Members | 2,643 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Must Declare the Scalar Variable error

Hi there,

Please take a look at the source code and tell me whats wrong?

Imports System.Data
Imports System.Data.Sql Client
Partial Class Test
Inherits System.Web.UI.P age
Const conString As String = "Data Source=.;Initia l
Catalog=Northwi nd;Integrated Security=True"
Public Function MyInsertMethod( ) As Integer
Dim con As New SqlConnection(c onString)
Dim insertString As String = "Exec usp_InsertTest
@CustomerID,@Fi rstName,@LastNa me"
Dim cmd As New SqlCommand(inse rtString, con)
con.Open()
cmd.ExecuteNonQ uery()
con.Close()
End Function
Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
Call MyInsertMethod( )
End Sub
End Class

I created a table Test with CustomerID nvarchar(50),Fi rstName
nchar(10),@Last Name nchar(10)

Along with the usp_InsertTest

set ANSI_NULLS ON
set QUOTED_IDENTIFI ER ON
GO
ALTER PROCEDURE [dbo].[usp_InsertTest]
(@CustomerID nvarchar(50),@F irstName nchar(10),@Last Name nchar(10))
AS
Insert into dbo.Test
(CustomerID,Fir stName,LastName )
Values
(@CustomerID,@F irstName,@LastN ame)
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
May 27 '06 #1
2 6685
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("@CustomerI D", "SomeCustID ")
cmd.Parameters. Add("@FirstName ", "John")
cmd.Parameters. Add("@LastName" , "DOE")

Check MSDN on SqlParameter for more information.
Regards.
"Oded Dror" <od******@cox.n et> wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hi there,

Please take a look at the source code and tell me whats wrong?

Imports System.Data
Imports System.Data.Sql Client
Partial Class Test
Inherits System.Web.UI.P age
Const conString As String = "Data Source=.;Initia l
Catalog=Northwi nd;Integrated Security=True"
Public Function MyInsertMethod( ) As Integer
Dim con As New SqlConnection(c onString)
Dim insertString As String = "Exec usp_InsertTest
@CustomerID,@Fi rstName,@LastNa me"
Dim cmd As New SqlCommand(inse rtString, con)
con.Open()
cmd.ExecuteNonQ uery()
con.Close()
End Function
Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
Call MyInsertMethod( )
End Sub
End Class

I created a table Test with CustomerID nvarchar(50),Fi rstName
nchar(10),@Last Name nchar(10)

Along with the usp_InsertTest

set ANSI_NULLS ON
set QUOTED_IDENTIFI ER ON
GO
ALTER PROCEDURE [dbo].[usp_InsertTest]
(@CustomerID nvarchar(50),@F irstName nchar(10),@Last Name nchar(10))
AS
Insert into dbo.Test
(CustomerID,Fir stName,LastName )
Values
(@CustomerID,@F irstName,@LastN ame)
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

May 28 '06 #2
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.n et> wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hi there,

Please take a look at the source code and tell me whats wrong?

Imports System.Data
Imports System.Data.Sql Client
Partial Class Test
Inherits System.Web.UI.P age
Const conString As String = "Data Source=.;Initia l
Catalog=Northwi nd;Integrated Security=True"
Public Function MyInsertMethod( ) As Integer
Dim con As New SqlConnection(c onString)
Dim insertString As String = "Exec usp_InsertTest
@CustomerID,@Fi rstName,@LastNa me"
Dim cmd As New SqlCommand(inse rtString, con)
con.Open()
cmd.ExecuteNonQ uery()
con.Close()
End Function
Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
Call MyInsertMethod( )
End Sub
End Class

I created a table Test with CustomerID nvarchar(50),Fi rstName
nchar(10),@Last Name nchar(10)

Along with the usp_InsertTest

set ANSI_NULLS ON
set QUOTED_IDENTIFI ER ON
GO
ALTER PROCEDURE [dbo].[usp_InsertTest]
(@CustomerID nvarchar(50),@F irstName nchar(10),@Last Name nchar(10))
AS
Insert into dbo.Test
(CustomerID,Fir stName,LastName )
Values
(@CustomerID,@F irstName,@LastN ame)
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

May 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
15799
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,
3
7791
by: Ken Adeniji | last post by:
Must declare the scalar variable '@FirstName' ContactGridViewWebForm.aspx <aspqlDataSource RunAt="server" ID="SqlDataSourceContact" ConnectionString="server=localhost;database=WordEngineering;Integrated Security=SSPI;" ProviderName="System.Data.OleDb"
1
7243
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 AND LANGUAGE = 'EN'
1
1815
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" AutoGenerateColumns="False" BackImageUrl="~/App_Themes/SkinFile/back1.jpg" BorderColor="Teal" BorderStyle="Solid" DataSourceID="SqlDataSource1"> <Columns> <asp:CommandField...
0
8315
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 records there is an error "Incorrect syntax near '-'. Must declare the scalar variable "@UserName". I worked out in design view,code is automatically generated.Iam not able fix the error. Iam working with Visual Web Developer-2005 Express Edition
2
23913
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
0
1348
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 CompareAllValues, I get the error: Must declare the scalar variable xxxx on fields that are not represented by controls in the formview templates. If all fields are there, it works fine, if not, I get the error, even though the fields are in all the...
1
2979
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" button in the gridview works just fine, but clicking the "Delete" button gives the error "Must Declare Scalar Variable @ServerName" yet the code in the UpdateCommand and DeleteCommand are essentially the same! I must be missing something basic...
1
8278
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 sure EMail address doesn't exist in database before I insert data. Connection string and everything else is correct. If I use Dim SQL = "Select * from Clients where EMail = " & chr(39) & "SomeEmailAddress@msn.com" & chr(39) it works fine.
0
8611
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8904
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.