Sunday, February 19, 2012

help regarding this search

//and i m getting this error

Syntax error converting the varchar value 'NPO04/136 ' to a column of data type int.

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: Syntax error converting the varchar value 'NPO04/136 ' to a column of data type int.

====================================

can anyone help me in this i m doing a search in a form ( for ex. u search for clientID n it'll come up in search result n once u select that it'll fill in the form) if anyone knw how to do this plz help me. thank u

Protected

Sub cmdSelect2_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles cmdSelect2.ClickDim sIDAsString

sID = lstResults.SelectedValue

Dim iIDAsInteger' iID = Int32.Parse(sID)'' If iID > 0 ThenDim selectSQLAsString

selectSQL =

"SELECT * FROM contactinfo "

selectSQL &=

"WHERE ClientID=@.ClientID"Dim cmdAsNew SqlCommand(selectSQL, conSR)

cmd.Parameters.AddWithValue(

"@.ClientID", iID)Dim readerAs SqlDataReader

Try

conSR.Open()

reader = cmd.ExecuteReader()

reader.Read()

' Fill the controls.'txtCaseid.Text = reader("Caseid").ToString()

txtClientID.Text = reader(

"ClientID").ToString()

txtFirstname.Text = reader(

"Client_Fname").ToString()

txtLastname.Text = reader(

"Client_Lname").ToString()

txtRace.Text = reader(

"Race").ToString()

txtCounty.Text = reader(

"County_of_origin").ToString()

txtGender.Text = reader(

"Gender").ToString()

txtState.Text = reader(

"State").ToString()

txtReligion.Text = reader(

"Religion").ToString()

txtContactID.Text = reader(

"ContactID").ToString()'reader.Close()'' enable_fields()

lblResults.Text =

""Catch exAs Exception'lblResults.Text = "Error inserting record"

lblResults.Text =

"Error inserting record"

lblResults.Text = ex.Message

Finally

conSR.Close()

EndTry

lblID.Text = sID

phID.Visible =

True

txtID.Text = sID

txtAct.Text =

"edit"

cmdSubmit.Text =

"Update"

lblCurrentAct.Text =

"Update Existing Record"'Else'If iID = 0 Then' lblResults.Text = "Client not found in Contact Information."'Else' lblResults.Text = "Please select a contact from the list."''' End IfEndSub

Hello my friend,

The field you wish to search by has non-numeric data in it so use a string to pass as the parameter instead of an int. You pass in iID so it crashes. Use a string variable instead and you should be fine.

Kind regards

Scotty

No comments:

Post a Comment