hi all,
currently my code is looping until 10 rows then it stop.let say user key in data for only 3rows the looping still run for other empty 7rows..i want the process will be if user key in 3 rows then data in database only has 3rows of value not like 3rows value, 7 rows empty(null)
here is my code:
Dim rowIndex As Integer = 0
Dim s As String = Convert.ToString(tarikh.Text)
Dim sc As New StringCollection()
If ViewState("CurrentTable") IsNot Nothing Then
Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
If dtCurrentTable.Rows.Count > 0 Then
For i As Integer = 1 To dtCurrentTable.Rows.Count
Dim stokereta As TextBox = DirectCast(grvBorang.Rows(rowIndex).Cells(1).FindControl("stokereta"), TextBox)
Dim ddl_jenisroda As DropDownList = DirectCast(grvBorang.Rows(rowIndex).Cells(2).FindControl("ddl_jenisroda"), DropDownList)
Dim nosiri As TextBox = DirectCast(grvBorang.Rows(rowIndex).Cells(3).FindControl("nosiri"), TextBox)
Dim saizroda As TextBox = DirectCast(grvBorang.Rows(rowIndex).Cells(4).FindControl("saizroda"), TextBox)
Dim flange As TextBox = DirectCast(grvBorang.Rows(rowIndex).Cells(5).FindControl("flange"), TextBox)
Dim hollow As TextBox = DirectCast(grvBorang.Rows(rowIndex).Cells(6).FindControl("hollow"), TextBox)
Dim ddl_tindakan As DropDownList = DirectCast(grvBorang.Rows(rowIndex).Cells(7).FindControl("ddl_tindakan"), DropDownList)
Dim ddl_skid As DropDownList = DirectCast(grvBorang.Rows(rowIndex).Cells(8).FindControl("ddl_skid"), DropDownList)
Dim catatan As TextBox = DirectCast(grvBorang.Rows(rowIndex).Cells(9).FindControl("catatan"), TextBox)
sc.Add(depohlist.SelectedValue + "," + lblsiri.Text + "," + kuantiti.Text + "," + s + "," + no_pendaftaran.Text + "," + stokereta.Text + "," + ddl_jenisroda.SelectedItem.Text + "," + nosiri.Text + "," + saizroda.Text + "," + flange.Text + "," + hollow.Text + "," + ddl_tindakan.SelectedValue + "," + ddl_skid.SelectedValue + "," + catatan.Text + "," + Label1.Text + "," + ulasandm.Text)
Private Sub InsertRecords(ByVal sc As StringCollection)
Dim conn As New SqlConnection(connectionString)
Dim sb As New StringBuilder(String.Empty)
Dim splitItems As String() = Nothing
For Each item As String In sc
Const sqlStatement As String = "Insert into butiran_hantar (depoh,siriSA,kuantiti,date,nodaftar,stokereta,jenisroda,nosiri,saizroda,flange,hollow,tindakan,skid,catatan,status,ulasandm) values"
If item.Contains(",") Then
splitItems = item.Split(",".ToCharArray())
sb.AppendFormat("{0}('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}'); ", sqlStatement, splitItems(0), splitItems(1), splitItems(2), splitItems(3), splitItems(4), splitItems(5), splitItems(6), splitItems(7), splitItems(8), splitItems(9), splitItems(10), splitItems(11), splitItems(12), splitItems(13), splitItems(14), splitItems(15))
End If
Next
Try
conn.Open()
Dim cmd As New SqlCommand(sb.ToString(), conn)
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
'Display a popup which indicates that the record was successfully inserted
Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "Script", "alert('Records Successfully Saved!');", True)
Catch ex As System.Data.SqlClient.SqlException
Dim msg As String = "Insert Error:"
msg += ex.Message
Throw New Exception(msg)
Finally
conn.Close()
End Try
End Sub
pls help me
musiw.