Question Defining Scalar Variables For Insertion into SQL

reidacus

New member
Joined
Sep 27, 2012
Messages
2
Programming Experience
Beginner
Hi All

I have a really simple web interface with is connected to an SQL server running MS SQL Server 2008. I essentially want the user to be able to enter values into the two text boxes provided and when the button is clicked, these values are inserted into the relevant table in the database.

When I run the code, I get an error back saying that the 'scalar variable for @clientName is not defined.' I have altered the insert statement to fixed values rather than entering from the text boxes and this works fine. Does anyone know how I can define these scalar variables. I'm not to sure what i'm missing. Code below. Thanks in advance for any help!

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DHCProjectConnectionString %>"
ProviderName="<%$ ConnectionStrings:DHCProjectConnectionString.ProviderName %>"
InsertCommand="INSERT INTO [Server] ([clientName], [serverName]) VALUES (@clientName, @serverName)">

<InsertParameters>
<asp:FormParameter Name="@clientName" Type="String" FormField="TextBox1" />
<asp:FormParameter Name="@serverName" Type="String" FormField="TextBox2" />
</InsertParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

P.S The code that the button executes is below

Partial Class Default2
Inherits System.Web.UI.Page

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
SqlDataSource1.Insert()
End Sub
End Class
 
Top Bottom