Good day,
can anyone help me in this code?!
I guess the code is totally right and doesn't require any change in it,,
however am getting an error which says "
Conversion failed when converting the varchar value '11/11/2010' to data type int."
check the attached file ..
can anyone help ASAP!!!!
Imports System.Data.SqlClient Imports System.Web.Configuration Partial Class Users_Sales_Form Inherits System.Web.UI.Page
Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
Dim objConnection As SqlConnection Dim objDataCommand As SqlCommand Dim sSQL As String Dim ConnectionString As String
Dim empID As Integer Dim Tdte As String 'Dim Tdate As Date Dim transID, TransLid As String 'Dim TLdate As Date Dim TLdte As String Dim proID, quan As String
empID = empidtxt.Text Tdte = transdttxt.Text 'Tdate = Convert.ToDateTime(transdttxt.Text.ToString) 'Tdate = transdttxt.Text = Date.Today() TransLid = tranlidtxt.Text 'TLdate = Convert.ToDateTime(transdttxt.Text.ToString) 'TLdate = transdttxt.Text = Date.Today() TLdte = transdttxt.Text proID = proidtxt.Text quan = quantitytxt.Text transID = transidtxt.Text
ConnectionString = WebConfigurationManager.ConnectionStrings("UCSConnectionString").ConnectionString
objConnection = New SqlConnection(ConnectionString) objConnection.Open()
sSQL = "Insert into Sales (Emp_id, T_dt)" & _ "values('" & empID & " ', ' " & Tdte & " ')"
objDataCommand = New SqlCommand(sSQL, objConnection) objDataCommand.ExecuteNonQuery()
sSQL = "Insert into Transaction_Line (TransL_id,Trans_id, TL_dt, Pro_id, Quantity)" & _ "values('" & TransLid & "', '" & TLdte & "', '" & proID & "', '" & quan & "', '" & transID & "')"
objDataCommand = New SqlCommand(sSQL, objConnection) objDataCommand.ExecuteNonQuery()
objConnection.Close()
End Sub End Class
|
Ankur GuptaPosted May 25, 2010, 6:28 AM
sSQL = "Insert into Transaction_Line (TransL_id,Trans_id, TL_dt, Pro_id, Quantity)" & _
"values('" & TransLid & "', '" & transID & "', '" & TLdte & "', '" & proID & "', '" & quan & "')"
Change transID Position in values it will be in 2nd position.
CrishPosted May 17, 2010, 12:28 PM
i think you have taken date field value int not datetime or varchar . That's why you are getting this error.
please change it to datetime.
Don't forget to Mark Do you like this Answer that solved your problem!
Ayesha balooshiPosted May 17, 2010, 9:40 AM
Trans_id: int
Pro_id: Varchar(15)
Quantity: numeric(4, 0)
Total_price: numeric(10, 2)
TL_dt: varchar(50)
Share_h_id: varchar(10)
For the TL_dt tried a dateandtime format but its not working at all it always retrieves an error... therefore i tried the varchar instead
DRISHTYPosted May 17, 2010, 9:37 AM
The error is coming due to this sentence,
sSQL = "Insert into Transaction_Line (TransL_id,Trans_id, TL_dt, Pro_id, Quantity)" & _
"values('" & TransLid & "', '" & TLdte & "', '" & proID & "', '" & quan & "', '" & transID & "')"
In that u r trying to insert..
TransL_id (int)- > TransLid (int),
Trans_id (int) - > TLdte (date),
TL_dt (date) -> proID (int),
Pro_id - > quan ,
Quantity - > transID
Ankur GuptaPosted May 17, 2010, 9:30 AM