0

Hello Friends,

I need one urgent help on this topic.

I have a database in mysql.
The column in table is of datatype time(0)

Similarly I have a control datetimepicker in vb.net
I have assigned format property as custom to the control and the CustomFormat property as HH:mm:ss tt so that it can just provide the time.
I dont want the date to be in it.

Issue comes when I try to retrieve the value from database
I get an error as Converion of type 'Timespan' to type 'Date' is not valid

Can anyone help me in this?

Try
   Dim myCommand As SqlCommand
   myCommand = New SqlCommand("select * from [HMS].[dbo].[DoctorSchedule] where DoctorID='" & txtDoctorID.Text & "'", Connection)
   Dim reader As SqlDataReader = myCommand.ExecuteReader
       While reader.Read
           TextBox1.Text = reader("ScheduledID")
           dtpMonST.Value = reader("MonST")
       End While

Catch ex As Exception
   MessageBox.Show("Error Connecting to Database: " & ex.Message)
End Try
3
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by poojavb
0

Is your database field is datetime or varchar

In MySql the column datatype is time(0)
In vb.net the type is time
But still its showing the conversion error

0

hello Pooja !
m not sure that the solution i m providing u is helpful for u or not , but i regularly using this thing in my projects , y not u try databinding and bindingsource , like this
take a bindingsource1

dim dt as new datatable
dim mycon as new sqlconnection("ur conn string")
mycon.open()
dim da as new sqldataadapter("ur command",mycon)
dt.table("mytable").clear
da.fill(dt,"mytable")
bindigsource1.datasource= dt.table("mytable")
'here u have to bindg ur form controls 
datetimepicker1.databind.add("text",bindingsource1,"__ur field in db__",false)' i use here text insteadof time , u can use time also
'with this u can also bind the textboxes and other controls on form

hope this will help u , and yes keep ur custom settings for ur datetime piker to just show time ,

Regards
M.Waqas Aslam

Edited by M.Waqas Aslam: to give some comments on code

0

The code did not work..

Its showing error as dt is not a member of DataTable and many more

Dim dt As New DataTable
Dim da As New SqlDataAdapter("SELECT * FROM [HMS].[dbo].[DoctorRegister]", Connection)
dt.Table("DoctorRegister").clear()
da.Fill(dt, "DoctorRegister")
BindingSource1.DataSource = dt.table("DoctorRegister")
dtpBreakFrom.databind.add("text", BindingSource1, "BreakFrom", False)
0

The code did not work..

Its showing error as dt is not a member of DataTable and many more

Dim dt As New DataTable
Dim da As New SqlDataAdapter("SELECT * FROM [HMS].[dbo].[DoctorRegister]", Connection)
dt.Table("DoctorRegister").clear()
da.Fill(dt, "DoctorRegister")
BindingSource1.DataSource = dt.table("DoctorRegister")
dtpBreakFrom.databind.add("text", BindingSource1, "BreakFrom", False)

Tried with something else....
thank u...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.