Can someone plese have a look at this for me and tell me why @userid is giving me a scaler error....
Protected Sub recordcount_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles recordcount.Click
Dim con As New Data.SqlClient.SqlConnection()
con.ConnectionString = ConfigurationManager.ConnectionStrings()("ConnectionString").ConnectionString
Dim cmd As New Data.SqlClient.SqlCommand()
cmd.CommandText = "select count (*) from images where (userid=@Userid)"
cmd.CommandType = Data.CommandType.Text
cmd.Connection = con
con.Open()
Dim result As Integer = cmd.ExecuteScalar()
con.Close()
If result > 0 Then
count.Text = result
If result < 0 Then
MsgBox(result)
End If
End If
End Sub
this is the form
<%@ Page Language="VB" debug="true" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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">
<h1>Test Site for running code</h1>
<div>
<asp:textbox ID="textbox1" runat="server"></asp:textbox><br /><br />
<asp:textbox id="textbox2" runat="server"></asp:textbox><br /><br />
<asp:button runat="server" text="Button" onclick="Unnamed2_Click" />
</div>
<asp:TextBox ID="Userid" runat="server"
Text='<%# Bind("Userid") %>'>
</asp:TextBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [id], [Imagename], [Userid] FROM [images] WHERE ([Userid] = @Userid)">
<SelectParameters>
<asp:ControlParameter ControlID="Userid" Name="Userid" PropertyName="Text"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="count" runat="server" Text="Label"></asp:Label>
<asp:Button ID="recordcount" runat="server" Text="count" />
</form>
</body>
</html>
i have tried all sorts of combinations to resolve it ....am i being stupid and maybe it isn't possible to get the data from a textbox for a query? all i'm trying to do is count how many files a member has uploaded?
look forward to your answers thanks
andy