|
-
Apr 20th, 2009, 12:12 AM
#1
Thread Starter
Lively Member
insert time in vb.net
i m inserting time from listview into sql database 2005.....but it results inserting both date and time part as well..but i want to insert only the time part...my code is below...thanks...plzz help
Code:
Dim conn As New SqlConnection("server=localhost;database=attendance1;uid=sa;password=;")
Dim i As Integer
For i = 0 To ListView1.Items.Count - 1
Dim cmd As New SqlCommand
cmd.Connection = conn
cmd.CommandText = "INSERT INTO shift (shift_name,on_duty_time,off_duty_time,beginning_in,ending_in,beginning_out,ending_out) VALUES (@shift_name,@on_duty_time,@off_duty_time,@beginning_in,@ending_in,@beginning_out,@ending_out) "
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@shift_name", ListView1.Items(i).SubItems(0).Text)
cmd.Parameters.AddWithValue("@on_duty_time", Convert.ToDateTime(ListView1.Items(i).SubItems(1).Text))
cmd.Parameters.AddWithValue("@off_duty_time", Convert.ToDateTime(ListView1.Items(i).SubItems(2).Text))
cmd.Parameters.AddWithValue("@beginning_in", Convert.ToDateTime(ListView1.Items(i).SubItems(3).Text))
cmd.Parameters.AddWithValue("@ending_in", Convert.ToDateTime(ListView1.Items(i).SubItems(4).Text))
cmd.Parameters.AddWithValue("@beginning_out", Convert.ToDateTime(ListView1.Items(i).SubItems(5).Text))
cmd.Parameters.AddWithValue("@ending_out", Convert.ToDateTime(ListView1.Items(i).SubItems(6).Text))
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Next i
ListView1.View = View.Details
MsgBox("ok")
-
Apr 20th, 2009, 12:25 AM
#2
Re: insert time in vb.net
This one ?
Code:
cmd.Parameters.AddWithValue("@ending_out", Convert.ToDateTime(ListView1.Items(i).SubItems(6).Text).ToShortTimeString())
Please mark you thread resolved using the Thread Tools as shown
-
Apr 20th, 2009, 12:35 AM
#3
Thread Starter
Lively Member
Re: insert time in vb.net
i used that and in the date part 1900-01-01 was inserted..still i m getting date part...
-
Apr 20th, 2009, 12:52 AM
#4
Re: insert time in vb.net
SQL Server columns cannot contain the time alone. That's why the column data type is 'datetime': it contains a date and a time. You simply have to ignore the date part when you read the data.
-
Apr 20th, 2009, 12:54 AM
#5
Re: insert time in vb.net
What is Your BackEnd. ? If it is SQL Server You cannot insert only time in if the Column type id DateTime or SmallDateTime. The other thing you can do is the change the column definition to varchar or char datatypes..
Edit: Little slow in typing
Please mark you thread resolved using the Thread Tools as shown
-
Apr 20th, 2009, 01:01 AM
#6
Thread Starter
Lively Member
Re: insert time in vb.net
i was thinking abt doing that but if i change datetime to varchar then would i be able to perform the time functions like adding time and all regarding that varchar text that i insert..
-
Apr 20th, 2009, 01:11 AM
#7
Re: insert time in vb.net
Then you have to neglect the Datepart while reading the values in your front end
Please mark you thread resolved using the Thread Tools as shown
-
Apr 20th, 2009, 01:20 AM
#8
Thread Starter
Lively Member
Re: insert time in vb.net
that's what i want to do.........if i insert both datetime then how can i extract only time part into textbox....
-
Apr 20th, 2009, 01:25 AM
#9
Re: insert time in vb.net
 Originally Posted by anirai
that's what i want to do.........if i insert both datetime then how can i extract only time part into textbox....
You've already asked that question in another thread and I've already provided an answer. I've asked you to post your current code and you have yet to do so. Please don't start asking the same question in multiple threads.
-
Apr 20th, 2009, 02:00 AM
#10
Thread Starter
Lively Member
Re: insert time in vb.net
oki....c ya in another thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|