List Info

Thread: DatagridView Insert record




DatagridView Insert record
country flaguser name
United States
2007-09-23 01:17:17
I have two table one is "employee info" contains
following fields;

1.	employeecode
2.	name
3.	department

Second table is "shift "contains following fields
1.	shift_in_time
2.	shift_duration
3.	shift_start_date
4.	employeecode

My form is like;

Tbshift_in_time           Tbshift_duration     
Tbshift_start_date


Datagridview;
Chk box column	Empcode	Name	department



Button1




I want when I click button1, command will take the
employeecode from
gatagridview (if check box is selected) and
shift_in_time,shift_duration,shift_start_date  from text box
and
insert into the shift table

My code is as follows, but it only inserts one record, I
want to
insert many records in a single click.


Dim cnn As SqlClient.SqlConnection = New
SqlClient.SqlConnection("Data
Source=133;Integrated Security=SSPI;Initial
Catalog=solutionhr")
        Dim insertcmd As String = "INSERT INTO
dbo.dtshift
(shiftintime, shiftduration, shiftstartdt, empcode)"
& _
        "values (shiftintime, shiftduration, shiftstartdt,
empcode)"


        Dim SelectedRows As Integer
        For Each SelectedRow As DataGridViewRow In
dgv.SelectedRows
            SelectedRow.Cells("yes").Value = True
        Next

        Dim prmcmd As New SqlClient.SqlCommand(insertcmd,
cnn)

        With prmcmd
            .Parameters.Add(New SqlParameter("shiftintime",
SqlDbType.DateTime)).Value = tbintime.Text
            .Parameters.Add(New SqlParameter("shiftduration",
SqlDbType.Money)).Value = tbduration.Text
            .Parameters.Add(New SqlParameter("shiftstartdt",
SqlDbType.SmallDateTime)).Value = tbstartdt.Text
            .Parameters.Add(New SqlParameter("empcode",
SqlDbType.Char)).Value = dgv.Item(1,
SelectedRows).Value.ToString
                    End With

        cnn.Open()
        prmcmd.ExecuteNonQuery()
        cnn.Close()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C# Community" group.
To post to this group, send email to csharpgooglegroups.com
To unsubscribe from this group, send email to
csharp-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/csharp?hl=en
-~----------~----~----~----~------~----~------~--~---


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )