Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am developing an app ,the problem is when i update a form the query runs properly and it update the other field but the date field wont update ,it set to its minimum value 1847 something like this. this is my code .
Dim dt As Date
                   dt = dtp_Expired.Value
                   sqlad.UpdateCommand = New SqlCommand(" UPDATE tbl_CustomerCard SET fld_custPhone = " & txt_Phone.Text & ", fld_ExpireDate = " & dt & " WHERE fld_CardNo = " & txt_MembershipID.Text & " ", sqlc)
                   Try
                       sqlad.UpdateCommand.ExecuteNonQuery()
                       MsgBox("Customer Data Update")
                   Catch ex As Exception
                       MsgBox(ex.Message)
                   End Try

Please help me in this , id dont know where i mistake
the date value comes from a datetime picker and its formate is like : 20/12/1991
thank u .
Posted

1 solution

Use parametrized query, like this one:
SQL
UPDATE tbl_CustomerCard SET fld_custPhone = @Phone, fld_ExpireDate = @Exdate WHERE fld_CardNo = @CardNo


Then call it using SQLParamterCollection[^] for SQLCommand[^].

For further information, please see:
How to: Perform Parameterized Queries[^]
SqlParameterCollection.AddWithValue Method[^]
 
Share this answer
 
Comments
Vipin Sharma 22-May-14 4:34am    
I also try this but it wont work , it update the customer no. but it reset the date to minimum date ,it don't update it correctly .
it set it to 28-07-1894 00:00:00
but not my selected date
[no name] 24-May-14 20:29pm    
I checked the statement and it worked fine! Means I had to vote very right....but I'm not right :( :-)
Maciej Los 25-May-14 4:24am    
Thank you, Bruno ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900