问题描述
你好
也许我,我完全错了-但是我现在花3天在这个$%&/(
Might me, I am totally wrong - but I spend now 3 days in this $%&/(
在表单的加载事件期间,我将 文本框组合框datetimepickers链接到表:Mytable
During the load event of the form, I link text-boxes comboboxes datetimepickers to a table: Mytable
公共类frmKalenderAnzeigen
私人BindingSource作为新的BindingSource
私有DataAdapter1作为新的Odbc.OdbcDataAdapter
将myTable变暗为新的DataTable
昏暗conn作为新的OdbcConnection
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(作为对象发送,作为EventArgs发送)处理MyBase.Load
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 =新的OdbcDataAdapter(strSql,conn)
DataAdapter1.Fill(myTable)
Dim strSql As String = "SELECT * FROM tbl_kal_termine limit 1"
DataAdapter1 = New OdbcDataAdapter(strSql, conn)
DataAdapter1.Fill(myTable)
'这里没有命令生成器,因为我将访问完全不同的记录
的mySql表中的
' no command builder here, because I will access a totally different record
' of my mySql table later
'DataGridView将被填充然后
' the DataGridView will be filled then
'我负责与文本框,组合框和dateTimePickers的数据绑定.
' 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")
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")
结束子
'现在,我要在Datagridview的一个单元格中处理click-Event
'如果点击了一个数字后跟#的单元格,那么我将更新文本框,组合框和datetimepickers的值,
'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,
'这很好.
私有子dataGridView1_CellClick(ByVal发送者作为对象,
ByVal e As DataGridViewCellEventArgs)_
处理DataGridView1.CellClick
'此事件来自dataGridView单元格上的滑动.
'单元格为空或没有数字后跟#,我们无需继续
暗淡的单元格作为字符串
一个空房间?
试试
单元格= DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
异常捕获
'一个空房间!
退出子
结束尝试
如果一个单元格中有一个带有#的数字,我们将继续
如果cell.ToString.IndexOf(#")> 0然后
退出子
如果结束
'该表已在表单的load事件中创建.
'所有文本框,组合框和日期时间选择器均已链接到该表
',因为我会为桌子摆放不同的餐具,所以我需要先清空桌子
myTable.Clear()
'将SQL字符串设置为记录,然后从odbc数据库中检索它.
Dim strSql As String ="SELECT * FROM tbl_kal_termine其中,terID = " & cell.Substring(0,cell.IndexOf(#")))
'使用sql-String
填充myTable
DataAdapter1 =新的OdbcDataAdapter(strSql,conn)
DataAdapter1.Fill(myTable)
'Erstelle einen Commandbuilder for插入,更新和删除
将commandbuilder1设置为新的OdbcCommandBuilder(DataAdapter1)
如果myTable.Rows.Count<> 0然后
'所有文本框,组合框和日期时间选择器都已填充!
BindingSource1.DataSource = myTable
'允许表格接受来自文本框,组合框和日期时间选择器的更改
myTable.AcceptChanges()
其他
MsgBox(无数据")
如果结束
结束子
私人子Update_Click(作为对象发送,作为EventArgs发送)处理更新.点击
'测试表myTable中的行和每个单元格中的内容
'我看到了在myTable表/每个单元格中所做的更改
昏暗的txt作为字符串=""
对于myTable.Rows中的每一行
对于myTable.Columns中的每一列
Console.Write(vbTab& row(column.ColumnName).ToString)
txt = row(column.ColumnName).ToString
下一个
下一行
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
'帮助
'将commandbuilder1调为新的OdbcCommandBuilder(DataAdapter1)
Me.BindingSource1.DataSource = myTable
DataAdapter1.Update(CType(Me.BindingSource1.DataSource,DataTable))
结束子
'Dim commandbuilder1 As New OdbcCommandBuilder(DataAdapter1)
Me.BindingSource1.DataSource = myTable
DataAdapter1.Update(CType(Me.BindingSource1.DataSource, DataTable))
End Sub
Vielen Dank Bruno
Vielen Dank Bruno
推荐答案
这篇关于如何更新文本框组合框datetimepickers-机会回到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!