Updating the table with conditon problem
Using SQL Server 2005, VB.Net
In my application am using 3 textbox
Textbox1.text = Date
Textbox2.text = TimeIn
Textbox3.text = TimeOut
I want to update my table by using the textbox value with condtion
For Example
Textbox1.text = 23/02/2009
Textbox2.text = 10:00 - HH:mm
Textbox3.text = 18:00
Query
update table1 set TimeIn = '" & Textbox2.Text & "', NewDate = case when CAST(LEFT('" & Textbox2.Text & "', 2) AS INT) > CAST(LEFT('" & Textbox3.Text & "', 2) AS INT) then '" & Textbox1.Text & "' + 1 else '" &am开发者_如何学Gop; Textbox1.Text & "' end, TimeOut = '" & Textbox3.Text & "' Where Date = '" & Textbox1.Text & "'
The above query is showing error as "Conversion failed when converting the varchar value '23/02/2009' to data type int"
Can any one give me a solution for this error.
Need Query Help.
Firstly you need to be using parameters rather than building the SQL statement using the string like your example, you don't want to fall victim to any SQL injection attacks. saftey warning over But that aside from that i thing :
`'" & Textbox1.Text & "' + 1 `
Should be
DATEADD(day, 1,'" & Textbox1.Text & "')
This will then add 1 day to your date
精彩评论