Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Syntax error converting the varchar value 'hgghjg' to a colu

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-13 : 06:28:28
sasireddy writes "This is the code in one form:

Private

Sub btntrack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntrack.Click

Dim con As New SqlConnection(ConfigurationSettings.AppSettings ("connectionstring"))

Dim tracknumber As Integer
con.Open()


Dim cmd As New SqlCommand("select TrackNumber, Origin, Destination, ExpectedDateOfDelivery, PresentDate, PresentLocation from tracking where TrackNumber= " & tracknumber, con)
cmd.Connection = con

Response.Redirect("details.aspx")

con.Close()


End Sub


This is the code in one more form:


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs ) Handles MyBase.Load

Dim con As New SqlConnection(ConfigurationSettings.AppSettings ("connectionstring"))

Dim TrackNumber As Integer

Dim cmd As New SqlCommand("select TrackNumber, Origin, Destination, ExpectedDateOfDelivery, PresentDate, PresentLocation from tracking where TrackNumber= " & TrackNumber, con)

'Dim cmd As New SqlCommand("select*from tracking", con)
con.Open()

DataGrid1.DataSource = cmd.ExecuteReader()

DataGrid1.DataBind()

con.Close()


End SubWhatever we give data it shows like this anna:

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

Source Error:

Line 32: con.Open()
Line 33: DataGrid1.DataSource = cmd.ExecuteReader()
Line 34: DataGrid1.DataBind()
Line 35: con.Close()
Line 36: End Sub
"

nr
SQLTeam MVY

12543 Posts

Posted - 2006-09-13 : 06:47:48
sounds like TrackNumber is a char
try


where TrackNumber= '" & TrackNumber & "'", con

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -