řešil jsem obdobný problém, vzhledem k tomu, že jsem DB soubor otvíral ručně, tak je vše ošetřeno programově. Přikládám kód k otevření DB a naplnění, snad pomůže.
If OfdOpenDB.ShowDialog = Windows.Forms.DialogResult.OK Then
'Try
ConnectString = "Provider = Microsoft.Jet.Oledb.4.0;Data Source=" + OfdOpenDB.FileName + ";"
DBConnection = New OleDb.OleDbConnection(ConnectString)
DBConnection.Open()
DBCmdStructInsert = New OleDb.OleDbCommand("INSERT INTO t_StructType (Name, Comment, Kind) VALUES(?,?,0);", DBConnection)
DBCmdStructInsert.Parameters.Add("Name", OleDbType.BSTR)
DBCmdStructInsert.Parameters.Add("Comment", OleDbType.BSTR)
DBCmdStructUpdate = New OleDb.OleDbCommand("UPDATE t_StructType SET Name = ?, Comment = ? WHERE ID = ?", DBConnection)
DBCmdStructUpdate.Parameters.Add("Name", OleDbType.BSTR)
DBCmdStructUpdate.Parameters.Add("Comment", OleDbType.BSTR)
DBCmdStructUpdate.Parameters.Add("IDNum", OleDbType.Decimal)
Dlg_Struct.DBCmdCntrlStructNameAdd = New OleDb.OleDbCommand("SELECT * FROM t_StructType WHERE (Name = ?)", DBConnection)
Dlg_Struct.DBCmdCntrlStructNameAdd.Parameters.Add("Name", OleDb.OleDbType.BSTR)
Dlg_Struct.DBCmdCntrlStructNameEdit = New OleDb.OleDbCommand("SELECT * FROM t_StructType WHERE (Name = ?) AND (Name <> ?)", DBConnection)
Dlg_Struct.DBCmdCntrlStructNameEdit.Parameters.Add("NameCh", OleDb.OleDbType.BSTR)
Dlg_Struct.DBCmdCntrlStructNameEdit.Parameters.Add("NameOr", OleDb.OleDbType.BSTR)
SqlStructSelect = "SELECT * FROM t_StructType ORDER BY ID;"
FillListBoxStructName()
GridChangeEnable = True
SqlMemberSelect = "SELECT t_StructMember.ID, t_StructType.Name AS [Str Name], t_StructType.Comment AS [Str Comment], t_StructMember.Member AS [Name], t_StructMember.Comment, Type, Offset, [Bit] " + _
"FROM (t_StructMember INNER JOIN t_StructType ON t_StructMember.StructID = t_StructType.ID)"
DBAdapter = New OleDb.OleDbDataAdapter(SqlMemberSelect + WhereString + ";", DBConnection)
'DBCommand = New OleDb.OleDbCommand(SqlMemberSelect + WhereString + ";", DBConnection)
'DBCommandDelete = New OleDb.OleDbCommand("DELETE * FROM t_StructMember;", DBConnection)
DBDataSetGrid.Clear()
DBLines = DBAdapter.Fill(DBDataSetGrid, "t_StructMember")
DataGridView1.AutoGenerateColumns = True
DataGridView1.DataSource = DBDataSetGrid.Tables("t_StructMember")
rozhodne se tu dá sposta věcí najít
|