how to correct error in searching for records using asp.net ?

I have form in asp.net that supposed to search for playerno record and prints out the following feilds:

PAYMENTNO,PLAYERNO,PEN_DATE,AMOUNT (Only 4 feilds)


but when i type palyerno in the text box i i get this erro .I be happy if some one help me solve this error.

error:

Server Error in '/asp' Application.
--------------------------------------------------------------------------------

Invalid column name 'PAYMENTNO'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'paymentno'.

Source Error:


Line 38: objAdapter = New SqlDataAdapter(objCommand)
Line 39: objDataSet = New DataSet()
Line 40: objAdapter.Fill(objDataSet)
Line 41:
Line 42: ' DataBind DG to DS


Source File: C:\aspscripts\aspx\tennisdbedit\db_search.aspx Line: 40



---------------------------------------------------------------------------------------------------------------------------------
my code:

<%@ Page Language="VB" Debug="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="VB" runat="server">

Sub btnSearch_OnClick(sender as Object, e as EventArgs)
Dim objConnection As SqlConnection
Dim objCommand As SqlCommand
Dim objAdapter As SqlDataAdapter
Dim objDataSet As DataSet
Dim strSearch As String
Dim strSQLQuery As String

' Get Search
strSearch = txtSearch.Text

' If there's nothing to search for then don't search
' o/w build our SQL Query and execute it.
If Len(Trim(strSearch)) > 0 Then
' Set up our connection.
objConnection = New SqlConnection("Data Source=(local);" _
& "Initial Catalog=teniss2;User Id=web;Password=web;" _
& "Connect Timeout=15;Network Library=dbmssocn;")


' Set up our SQL query text.
strSQLQuery = "SELECT PAYMENTNO,PLAYERNO,PEN_DATE,AMOUNT " _
& "FROM penalites " _
& "WHERE playerno LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "ORDER BY playerno;"

' Create new command object passing it our SQL query
' and telling it which connection to use.
objCommand = New SqlCommand(strSQLQuery, objConnection)

' Get a DataSet to bind the DataGrid to
objAdapter = New SqlDataAdapter(objCommand)
objDataSet = New DataSet()
objAdapter.Fill(objDataSet)

' DataBind DG to DS
dgPaging.DataSource = objDataSet
dgPaging.DataBind()

objConnection.Close()
Else
txtSearch.Text = "Enter Search Here"
End If
End Sub

</script>
<html>
<head>
<title>ASP.NET Database Search</title>
</head>
<body>

<form runat="server">

<p>Search our sample db by first or last name. (% returns all)</p>

<asp:TextBox id="txtSearch" runat="server" />

<asp:Button id="btnSearch" runat="server"
Text = "Search"
OnClick = "btnSearch_OnClick"
/>

<p>[Try 'am' or 'er' for an example]</p>

<!-- Plain vanilla DataGrid... format it as you like. -->
<asp:DataGrid id="dgPaging" runat="server"
HeaderStyle-Font-Bold="True"
/>

</form>

<hr />

<p>
Click <a href=http://www.webdeveloper.com/forum/archive/index.php/".asp">here</a>
to read about and Download the source code.
</p>

</body>because you are looking for payment

strSQLQuery = "SELECT payment, penalty_date, amount, playerno" _Many thanks to u reply. I did the changes but still it complains about the paymentno!! line 40 as above!!!It now says that you have a 't' there

Invalid column name 'PAYMENTNOt'.

EricIt now says that you have a 't' there

Invalid column name 'PAYMENTNOt'.

Eric

opss that was a type mistake . I changed that to paymentno but sitll same error about paymentno!!Since it's taking a dump when you're trying to do the fill, I'd suggest that you check the "penalites" table to see if the column name is exactly what you think it is.Since it's taking a dump when you're trying to do the fill, I'd suggest that you check the "penalites" table to see if the column name is exactly what you think it is.

Thanks for u reply. i check the penalties table in sql server and the column name is paymentno . Unfortunely i can not post an image other wise i was posting what i was seeing in query analyzer. Hope some one help fix this erro.ThanksAre you positive you do not have a typo? you switch letters in your db column? making in your code?

EricAnother possibility exists if you have multiple tables with the same name, but different owners, in which case, if you're not specifying the database owner, you might be getting a table other than the one you intended, which might actually lack the field or have it misspelled. Or, in similar fashion, having on the server multiple databases containing the same table name and using the wrong database. Or multiple servers etc. so forth...

Does the query work if you paste it into Query Analyzer and run it there?

Wait as sec... your code says "FROM penalites" and you say "the penalties table"... Is that a typo in your post, or was it a direct copy and paste from code? Do both tables exist, one different than the other?
 
Back
Top