problem with inserting data

getnitha

Member
Joined
Jul 16, 2007
Messages
14
Programming Experience
1-3
hi i am trying to insert multiple records into a table by selecting it from another table.but its inserting just one entire record only,not inserting rest.i think problem s with my loop construction
can anyone plse help me o solve this


<code>


Dim dst As New DataSet
Dim sqlCmd As New SqlCommand
Dim sqlDA As SqlDataAdapter
Dim dar As DataRow
Conn12.ConnectionString = connString
Conn12.Open()
Dim dtbDataTable As New DataTable

sqlCmd = New SqlCommand("select USER_CREATION.User_ID,USER_CREATION.User_Name,T_TNA_LOG.D_EVENT_DATE,T_TNA_LOG.N_EVENT from T_TNA_LOG,USER_CREATION where T_TNA_LOG.S_USER_ID = USER_CREATION.User_ID", Conn12)

sqlDA = New SqlDataAdapter(sqlCmd)
sqlDA.Fill(dst)
Try
Dim cmdDs As New DataSet
Dim countCmd As New SqlCommand
Dim cmdCount As SqlDataAdapter
Dim darold As DataRow
countCmd = New SqlCommand("Select T_TNA_LOG.N_EVENT,T_TNA_LOG.D_EVENT_DATE from T_TNA_LOG,USER_CREATION where T_TNA_LOG.S_USER_ID = USER_CREATION.User_ID ", Conn12)
cmdCount = New SqlDataAdapter(countCmd)
cmdCount.Fill(cmdDs)



Dim cmdDs1 As New DataSet
Dim countCmd1 As New SqlCommand
Dim count1 As Integer
Dim cmdCount1 As SqlDataAdapter
countCmd1 = New SqlCommand("Select * from Temp_Attendence", Conn12)
cmdCount1 = New SqlDataAdapter(countCmd1)
cmdCount1.Fill(cmdDs1)
count1 = cmdDs1.Tables(0).Rows.Count
Conn12.Close()

//i thk from here its creatng problem

For Each dar In dst.Tables(0).Rows
For Each darold In cmdDs.Tables(0).Rows



If (darold(0) = 16) Then
TextBox5.Text = darold(1).ToString().Substring(10, 8)
MsgBox(TextBox5.Text)
'End If
ElseIf (darold(0) = 18) Then
TextBox6.Text = darold(1).ToString().Substring(10, 8)
MsgBox(TextBox6.Text)
'End If
ElseIf (darold(0) = 19) Then
TextBox7.Text = darold(1).ToString().Substring(10, 8)
MsgBox(TextBox7.Text)
'End If
ElseIf (darold(0) = 17) Then
TextBox8.Text = darold(1).ToString().Substring(10, 8)
MsgBox(TextBox8.Text)
End If
Next


Dim cmdSql As New SqlCommand
Conn1.ConnectionString = connString

If count1 = 0 Then
Conn1.Open()

sql1 = "insert into Temp_Attendence(User_ID,User_Name,Punch_Date,Time_In,Break_Out,Break_In,Time_Out,Delay_Time,Over_Time,Actual_Hour,Total_Late_Hours,Total_Time) values ('" + dar(0) + "','" + dar(1) + "','" + dar(2).ToString().Substring(0, 10) + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + "" + "','" + "" + "','" + "" + "','" + "" + "','" + "')"
cmdSql = New SqlCommand(sql1, Conn1)
cmdSql.ExecuteNonQuery()

Conn1.Close()
End If
Next
Conn12.Close()
Catch excp As Exception
MsgBox(excp.ToString())
End Try
 
Back
Top