D
db1sbg
Guest
Hello,
Might me, I am totally wrong - but I spend now 3 days in this $%&/(
During the load event of the form, I link text-boxes comboboxes datetimepickers to a table: Mytable
Public Class frmKalenderAnzeigen
Private BindingSource As New BindingSource
Private DataAdapter1 As New Odbc.OdbcDataAdapter
Dim myTable As New DataTable
Dim conn As New OdbcConnection
Private Sub frmKalenderAnzeigen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strSql As String = "SELECT * FROM tbl_kal_termine limit 1"
DataAdapter1 = New OdbcDataAdapter(strSql, conn)
DataAdapter1.Fill(myTable)
no command builder here, because I will access a totally different record
of my mySql table later
the DataGridView will be filled then
I take care of the databinding to the textboxes, comboboxes and dateTimePickers.
txtID.DataBindings.Add("TEXT", myTable, "terID")
txtVon.DataBindings.Add("TEXT", myTable, "terVon")
txtBis.DataBindings.Add("TEXT", myTable, "terBis")
txtWas.DataBindings.Add("TEXT", myTable, "terWas")
txtWo.DataBindings.Add("TEXT", myTable, "terWo")
txtMehr.DataBindings.Add("TEXT", myTable, "terKommentar")
DateTimePicker.DataBindings.Add("TEXT", myTable, "terDatum")
cboAuftrag.DataBindings.Add("TEXT", myTable, "terAuftragId")
cboWer.DataBindings.Add("TEXT", myTable, "terWerID")
End Sub
Now I take care of a click-Event in one cell of the Datagridview
if a cell with a number, followed by a # is clicked, then I update the values of the textbox, comboboxes and datetimepickers,
This works fine.
Private Sub dataGridView1_CellClick(ByVal sender As Object,
ByVal e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellClick
this event comes from a klick on a dataGridView cell.
either the cell is empty or has not number followed by a #, We do not need to continue
Dim cell As String
an empty cell?
Try
cell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
Catch ex As Exception
an empty cell!
Exit Sub
End Try
If a cell has a number with a # in it, We will continuge
If cell.ToString.IndexOf("#") > 0 Then
Exit Sub
End If
The table has been created in the load event of the form.
all textboxes, comboboxes and datetimepickers have been linked to this table
because I will vocus on a total different set for the table, I need to clear the table first
myTable.Clear()
Set up the SQL String to the record and retrieve it from the odbc Database.
Dim strSql As String = "SELECT * FROM tbl_kal_termine where terID = " & cell.Substring(0, cell.IndexOf("#"))
fill myTable using the sql-String
DataAdapter1 = New OdbcDataAdapter(strSql, conn)
DataAdapter1.Fill(myTable)
Erstelle einen Commandbuilder für Insert, Update und Delete
Dim commandbuilder1 As New OdbcCommandBuilder(DataAdapter1)
If myTable.Rows.Count <> 0 Then
all textboxes, comboboxes and datetimepickers are filled!
BindingSource1.DataSource = myTable
Allow the table to accept changes from the textboxes, comboboxes and datetimepickers
myTable.AcceptChanges()
Else
MsgBox("no data")
End If
End Sub
Private Sub Update_Click(sender As Object, e As EventArgs) Handles Update.Click
to test what Is in row And each cell in the table myTable
I see the changes I made in the myTable table / in each cell
Dim txt As String = ""
For Each row In myTable.Rows
For Each column In myTable.Columns
Console.Write(vbTab & row(column.ColumnName).ToString)
txt = row(column.ColumnName).ToString
Next
Next row
I think, i mixed up and failed here. What would be the right code?
I see no error but also no changes to the database
HELP
Dim commandbuilder1 As New OdbcCommandBuilder(DataAdapter1)
Me.BindingSource1.DataSource = myTable
DataAdapter1.Update(CType(Me.BindingSource1.DataSource, DataTable))
End Sub
Vielen Dank Bruno
Continue reading...
Might me, I am totally wrong - but I spend now 3 days in this $%&/(
During the load event of the form, I link text-boxes comboboxes datetimepickers to a table: Mytable
Public Class frmKalenderAnzeigen
Private BindingSource As New BindingSource
Private DataAdapter1 As New Odbc.OdbcDataAdapter
Dim myTable As New DataTable
Dim conn As New OdbcConnection
Private Sub frmKalenderAnzeigen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strSql As String = "SELECT * FROM tbl_kal_termine limit 1"
DataAdapter1 = New OdbcDataAdapter(strSql, conn)
DataAdapter1.Fill(myTable)
no command builder here, because I will access a totally different record
of my mySql table later
the DataGridView will be filled then
I take care of the databinding to the textboxes, comboboxes and dateTimePickers.
txtID.DataBindings.Add("TEXT", myTable, "terID")
txtVon.DataBindings.Add("TEXT", myTable, "terVon")
txtBis.DataBindings.Add("TEXT", myTable, "terBis")
txtWas.DataBindings.Add("TEXT", myTable, "terWas")
txtWo.DataBindings.Add("TEXT", myTable, "terWo")
txtMehr.DataBindings.Add("TEXT", myTable, "terKommentar")
DateTimePicker.DataBindings.Add("TEXT", myTable, "terDatum")
cboAuftrag.DataBindings.Add("TEXT", myTable, "terAuftragId")
cboWer.DataBindings.Add("TEXT", myTable, "terWerID")
End Sub
Now I take care of a click-Event in one cell of the Datagridview
if a cell with a number, followed by a # is clicked, then I update the values of the textbox, comboboxes and datetimepickers,
This works fine.
Private Sub dataGridView1_CellClick(ByVal sender As Object,
ByVal e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellClick
this event comes from a klick on a dataGridView cell.
either the cell is empty or has not number followed by a #, We do not need to continue
Dim cell As String
an empty cell?
Try
cell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
Catch ex As Exception
an empty cell!
Exit Sub
End Try
If a cell has a number with a # in it, We will continuge
If cell.ToString.IndexOf("#") > 0 Then
Exit Sub
End If
The table has been created in the load event of the form.
all textboxes, comboboxes and datetimepickers have been linked to this table
because I will vocus on a total different set for the table, I need to clear the table first
myTable.Clear()
Set up the SQL String to the record and retrieve it from the odbc Database.
Dim strSql As String = "SELECT * FROM tbl_kal_termine where terID = " & cell.Substring(0, cell.IndexOf("#"))
fill myTable using the sql-String
DataAdapter1 = New OdbcDataAdapter(strSql, conn)
DataAdapter1.Fill(myTable)
Erstelle einen Commandbuilder für Insert, Update und Delete
Dim commandbuilder1 As New OdbcCommandBuilder(DataAdapter1)
If myTable.Rows.Count <> 0 Then
all textboxes, comboboxes and datetimepickers are filled!
BindingSource1.DataSource = myTable
Allow the table to accept changes from the textboxes, comboboxes and datetimepickers
myTable.AcceptChanges()
Else
MsgBox("no data")
End If
End Sub
Private Sub Update_Click(sender As Object, e As EventArgs) Handles Update.Click
to test what Is in row And each cell in the table myTable
I see the changes I made in the myTable table / in each cell
Dim txt As String = ""
For Each row In myTable.Rows
For Each column In myTable.Columns
Console.Write(vbTab & row(column.ColumnName).ToString)
txt = row(column.ColumnName).ToString
Next
Next row
I think, i mixed up and failed here. What would be the right code?
I see no error but also no changes to the database
HELP
Dim commandbuilder1 As New OdbcCommandBuilder(DataAdapter1)
Me.BindingSource1.DataSource = myTable
DataAdapter1.Update(CType(Me.BindingSource1.DataSource, DataTable))
End Sub
Vielen Dank Bruno
Continue reading...