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.
Code Behind:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Data.SqlClient
Public Class _Default
Inherits System.Web.UI.Page
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
con.Open()
cmd.CommandText = "SELECT [ItemNumber], [ItemUPC] FROM [_NoLock_FS_Item] WHERE ([ItemUPC] = '" & UPCText.Text & "')"
cmd.ExecuteNonQuery()
GridView1.DataBind()
cmd.Dispose()
con.Close()
End If
'End If
End Sub
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."
Bookmarks