Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Help naman sa VB Net Datagridview.

mateo33

Novice
Advanced Member
Messages
32
Reaction score
0
Points
26
Ito yung sample save function ko, ang problema ay di nya nasasave ang new row sa datagridview, or ayaw nya mag-add ng new row at error lagi lumalabas, pa help naman mga master, school project po, TIA sa makakatulong.

Public Function SaveAccntInfo(usr As String)
Dim successful As Boolean
If gridchanged Then 'If changes made in datagridview
Try
Using con9 As New OleDbConnection(AI_Str)
con9.Open()
Using cmd9 As New OleDbCommand("SELECT * FROM [" & usr & "]", con9)
Using adapter As New OleDbDataAdapter(cmd9)
Dim dt As DataTable = DirectCast(AI_DGV.DataSource, DataTable)
Dim updCom As New OleDbCommand("UPDATE [" & usr & "] SET [LogInDate] = ?, etc. . . .")
Dim insCom As New OleDbCommand("INSERT INTO [" & usr & "] ([LogInDate], etc . . .")
Dim delCom As New OleDbCommand("DELETE FROM [" & usr & "] WHERE [LogInDate] = code", con9)
For Each rows As DataGridViewRow In AI_DGV.Rows
For Each cell As DataGridViewCell In rows.Cells
Dim dateval As DateTime
Dim doubleval As Double
If rows.IsNewRow AndAlso newRow = True Then
With insCom
'INSERT add parameters here
If rows.Cells("LogInDate") IsNot Nothing AndAlso rows.Cells("LogInDate").Value IsNot Nothing AndAlso Not String.IsNullOrWhiteSpace(rows.Cells("LogInDate").Value.ToString()) Then
If Date.TryParseExact(rows.Cells("LogInDate").Value.ToString(), formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, dateval) Then
.Parameters.Add("@[LogInDate]", OleDbType.Date).Value = dateval
Else
.Parameters.AddWithValue("@[LogInDate]", Date.Now)
End If
Else
.Parameters.AddWithValue("@[LogInDate]", Date.Now)
End If
End With
'Other Insert add parameters here
ElseIf Not rows.IsNewRow Then
With updCom
'UPDATE parameters here
If rows.Cells("LogInDate") IsNot Nothing AndAlso rows.Cells("LogInDate").Value IsNot Nothing AndAlso Not String.IsNullOrWhiteSpace(rows.Cells("LogInDate").Value.ToString()) Then
If Date.TryParseExact(rows.Cells("LogInDate").Value.ToString(), formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, dateval) Then
.Parameters.Add("@[LogInDate]", OleDbType.Date).Value = dateval
Else
.Parameters.AddWithValue("@[LogInDate]", Date.Now)
End If
Else
.Parameters.AddWithValue("@[LogInDate]", Date.Now)
End If
'Other UPDATE parameters here
End With
adapter.UpdateCommand = updCom
adapter.InsertCommand = insCom
adapter.DeleteCommand = delCom
Try
adapter.Update(dt)
dt.AcceptChanges()
successful = True
Catch ex As Exception
successful = False
MsgBox(ex.ToString)
End Try
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show("An error occurred: " & ex.Message)
End Try
End If
Return successful
End Function
 
Back
Top Bottom