April 21, 2011 at 12:23 pm
I do not know if I am in the right thread, but I am having a SQL issue.
When I debug my web-page it shows me this error:
Must declare the variable '@Name'.
Here is my SQLdatasource
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"
InsertCommand="INSERT INTO [Customer] ([Name], [Address], [City], [State], [ZipCode], [Phone], [DueDate], [EmployeeName], [Copies], [PaperSize], [PaperCode], [Sides], [Binding], [BindingCover], [Staples], [Folding], [DesktopPublishing]) VALUES (@Name, @Address, @City, @State, @ZipCode, @DueDate, @EmployeeName, @Copies, @PaperSize, @PaperCode, @Sides, @Binding, @BindingCover, @Staples, @Folding, @DesktopPublishing)"
ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>"
SelectCommand="SELECT WorkOrderID, Name, Address, City, State, ZipCode, Phone, DueDate, EmployeeName, Copies, PaperSize, PaperCode, Sides, Binding, BindingCover, Staples, Folding, DesktopPublishing FROM dansari.dbo.Customer INNER JOIN dansari.dbo.WorkOrder ON Customer.CustomerID = WorkOrder.CustomerID">
</asp:SqlDataSource>
What is happening?
April 21, 2011 at 12:59 pm
dianaansari (4/21/2011)
I do not know if I am in the right thread, but I am having a SQL issue.When I debug my web-page it shows me this error:
Must declare the variable '@Name'.
Here is my SQLdatasource
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"
InsertCommand="INSERT INTO [Customer] ([Name], [Address], [City], [State], [ZipCode], [Phone], [DueDate], [EmployeeName], [Copies], [PaperSize], [PaperCode], [Sides], [Binding], [BindingCover], [Staples], [Folding], [DesktopPublishing]) VALUES (@Name, @Address, @City, @State, @ZipCode, @DueDate, @EmployeeName, @Copies, @PaperSize, @PaperCode, @Sides, @Binding, @BindingCover, @Staples, @Folding, @DesktopPublishing)"
ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>"
SelectCommand="SELECT WorkOrderID, Name, Address, City, State, ZipCode, Phone, DueDate, EmployeeName, Copies, PaperSize, PaperCode, Sides, Binding, BindingCover, Staples, Folding, DesktopPublishing FROM dansari.dbo.Customer INNER JOIN dansari.dbo.WorkOrder ON Customer.CustomerID = WorkOrder.CustomerID">
</asp:SqlDataSource>
What is happening?
Words preceeded by an @ are variables in SQL Server. You have to delcare them before you can use them. It looks like you're trying to insert the contents of a bunch of variables into a table without defining the variables or assigning values to those variables. I'd bet that if you managed to just define @Name, you'll get an error that says @Address isn't defined.
What are you trying to put into your Customer table?
--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
April 21, 2011 at 1:10 pm
I am trying to insert the customer information in the customer table. The customer table has a relationship with the WorkOrder table (which has the columns Copies and so on).
I am kind of new at this, but how do I declare the values?
April 21, 2011 at 1:14 pm
you can declare a varialbe with the below. you will have to research them though and see what the appropriate data type is for the table.
Declare @Name VarChar(50)
Set @name='Mighty Mouse'
Is this from a stored procedure? The error windo you have posted suggests it is not the standard query window.
Dan
If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.
April 21, 2011 at 1:37 pm
I am using SQL to enter data from asp.net/c# language. A link button on asp.net webpage will allow the user to enter the data into and that data will go into an SQL database.
April 21, 2011 at 1:52 pm
in that case you likely whant to replace the variables with the actual values before you send the input over from asp or are you simply calling a stored procedure form asp?
Dan
If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.
April 21, 2011 at 2:03 pm
dianaansari (4/21/2011)
I am using SQL to enter data from asp.net/c# language. A link button on asp.net webpage will allow the user to enter the data into and that data will go into an SQL database.
I'd suggest using stored procedures to insert this data. Then you don't have to worry about declaring the variables as it'll already be done for you and you'll just have to pass the information you want. You won't even have to have INSERT statements on your asp page.
--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
April 21, 2011 at 2:25 pm
dianaansari (4/21/2011)
I do not know if I am in the right thread, but I am having a SQL issue.When I debug my web-page it shows me this error:
Must declare the variable '@Name'.
Here is my SQLdatasource
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"
InsertCommand="INSERT INTO [Customer] ([Name], [Address], [City], [State], [ZipCode], [Phone], [DueDate], [EmployeeName], [Copies], [PaperSize], [PaperCode], [Sides], [Binding], [BindingCover], [Staples], [Folding], [DesktopPublishing]) VALUES (@Name, @Address, @City, @State, @ZipCode, @DueDate, @EmployeeName, @Copies, @PaperSize, @PaperCode, @Sides, @Binding, @BindingCover, @Staples, @Folding, @DesktopPublishing)"
ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>"
SelectCommand="SELECT WorkOrderID, Name, Address, City, State, ZipCode, Phone, DueDate, EmployeeName, Copies, PaperSize, PaperCode, Sides, Binding, BindingCover, Staples, Folding, DesktopPublishing FROM dansari.dbo.Customer INNER JOIN dansari.dbo.WorkOrder ON Customer.CustomerID = WorkOrder.CustomerID">
</asp:SqlDataSource>
What is happening?
This is more of a .NET config issue than a SQL issue...you're hunch about it being the right forum was warranted 🙂
I do not use <asp:SqlDataSource> myself but I'll take a shot at this to see if I can help. Your InsertCommand looks fine...but it appears you are missing the mappings between your form fields and the SQL variable names. You do this in the <insertparameters> collection. For you it would look something like this:
<insertparameters>
<asp:formparameter name="Name" formfield="CustomerNameInputBox" />
<asp:formparameter name="Address" formfield="CustomerAddressInputBox" />
<!-- the rest of the field mappings go here -->
</insertparameters>
See this article: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insertcommand.aspx
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
April 21, 2011 at 2:27 pm
PS I agree with Stefan, favor stored procedures over embedded SQL. There is a section in the article from my previous post that shows an example using a stored procedure instead of embedded SQL.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply