I have been battling with this for WAY too long for how simple it should be lol
I am trying to create a basic webpage that will check a column of a database table to see if a "UPC Code" is taken already, to prevent duplicate use. I'm fairly new at .NET programming, but have built asp pages before. I'm just stumped :/
I have a textbox that a user can type in a number. The page successfully checks to see if the textbox is blank and reports the error, and if there is a value, it's supposed to bind that textbox number to a gridview to see which Item# it's associated with. But for some reason, my code is not binding the value of the textbox to the gridview.
Public Class _Default
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("FSDBGLConnectionString").ConnectionString)
Dim cmd As SqlCommand = con.CreateCommand()
If IsPostBack Then
cmd.CommandText = "SELECT [ItemNumber], [ItemUPC] FROM [_NoLock_FS_Item] WHERE ([ItemUPC] = '" & UPCText.Text & "')"
Sub CheckUPC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckUPC.Click
If UPCText.Text = "" Then
lblErrorMessage.Text = "Please enter a UPC Code to check."
I have this fixed now, it was a small thing I was missing in my code behind (i knew it was going to be a simple thing...
Here's the changes I made to get it working properly:
cmd.CommandText = "SELECT [ItemNumber], [ItemUPC] FROM [_NoLock_FS_Item] WHERE ([ItemUPC] = @UPC)"