Question Defining Scalar Variables For Insertion into SQL


New member
Sep 27, 2012
Programming Experience
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" "">

<html xmlns="">
<head runat="server">
<form id="form1" runat="server">

<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)">

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


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
End Sub
End Class
Top Bottom