Can't figure it out. Please help!!!

[b][red]This message was edited by VB Newbie at 2004-6-30 11:24:2[/red][/b][hr]
[b][red]This message was edited by VB Newbie at 2004-6-30 11:22:41[/red][/b][hr]
Hi,

I have created an access database programaticly.
[code]
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table

'Create NewDB Database.
'Change the path to the new .mdb file as appropriate. Make sure the folder
'provided in the path exists. If you path name is not specified, the
'database will be created in your application folder.
cat = New ADOX.Catalog()
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:AccessDBNewDB.mdb;")
'Create a new table
tbl = New ADOX.Table()
tbl.Name = "TestTable"
tbl.Columns.Append("Product description")
tbl.Columns.Append("Price")
tbl.Columns.Append("ID", DataTypeEnum.adInteger)
cat.Tables.Append(tbl)
[/code]

Now I want this to be displayed in a DataGrid so that a user can put his own data into the DataGrid and saves it back to the original Access datafile (NewDB.mdb).

Simple question: HOW?!!!!!

I suppose I need an:
- connection
[code]
Dim con As New ADODB.Connection()
[/code]
or:
[code]
Dim con As New SqlClient.SqlConnection("Data Source=C:AccessDBNewDB.mdb")
[/code]
and an adapter:
[code]
Dim DA As New SqlClient.SqlDataAdapter("SELECT Product description, Price, ID FROM TestTable", con)
[/code]
or:
[code]
Dim DA As New OleDb.OleDbDataAdapter("SELECT Product description, Price, ID FROM TestTable", con)
[/code]
and a DataSet:
[code]
Private m_DataSet As DataSet
' Build the DataSet.
m_DataSet = New DataSet()
Dim dt_students As New DataTable("TestTable")
m_DataSet.Tables.Add(dt_students)
dt_students.Columns.Add("Product description", GetType(String))
dt_students.Columns.Add("Price", GetType(String))
dt_students.Columns.Add("ID", GetType(Integer))

' Bind the DataGrid to the DataSet.
DataGrid1.DataSource = m_DataSet
[/code]

Anyway, it still wont work.
I dont even know if i must use an ADODB or sql or Ole.
(dont even know the differences)

But if anyone knows the correct code to let things work, please let me know!


Thanks,

VB Newbie




Comments

  • : [b][red]This message was edited by VB Newbie at 2004-6-30 11:24:2[/red][/b][hr]
    : [b][red]This message was edited by VB Newbie at 2004-6-30 11:22:41[/red][/b][hr]
    : Hi,
    :
    : I have created an access database programaticly.
    : [code]
    : Dim cat As ADOX.Catalog
    : Dim tbl As ADOX.Table
    :
    : 'Create NewDB Database.
    : 'Change the path to the new .mdb file as appropriate. Make sure the folder
    : 'provided in the path exists. If you path name is not specified, the
    : 'database will be created in your application folder.
    : cat = New ADOX.Catalog()
    : cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
    : "Data Source=C:AccessDBNewDB.mdb;")
    : 'Create a new table
    : tbl = New ADOX.Table()
    : tbl.Name = "TestTable"
    : tbl.Columns.Append("Product description")
    : tbl.Columns.Append("Price")
    : tbl.Columns.Append("ID", DataTypeEnum.adInteger)
    : cat.Tables.Append(tbl)
    : [/code]
    :
    : Now I want this to be displayed in a DataGrid so that a user can put his own data into the DataGrid and saves it back to the original Access datafile (NewDB.mdb).
    :
    : Simple question: HOW?!!!!!
    :
    : I suppose I need an:
    : - connection
    : [code]
    : Dim con As New ADODB.Connection()
    : [/code]
    : or:
    : [code]
    : Dim con As New SqlClient.SqlConnection("Data Source=C:AccessDBNewDB.mdb")
    : [/code]
    : and an adapter:
    : [code]
    : Dim DA As New SqlClient.SqlDataAdapter("SELECT Product description, Price, ID FROM TestTable", con)
    : [/code]
    : or:
    : [code]
    : Dim DA As New OleDb.OleDbDataAdapter("SELECT Product description, Price, ID FROM TestTable", con)
    : [/code]
    : and a DataSet:
    : [code]
    : Private m_DataSet As DataSet
    : ' Build the DataSet.
    : m_DataSet = New DataSet()
    : Dim dt_students As New DataTable("TestTable")
    : m_DataSet.Tables.Add(dt_students)
    : dt_students.Columns.Add("Product description", GetType(String))
    : dt_students.Columns.Add("Price", GetType(String))
    : dt_students.Columns.Add("ID", GetType(Integer))
    :
    : ' Bind the DataGrid to the DataSet.
    : DataGrid1.DataSource = m_DataSet
    : [/code]
    :
    : Anyway, it still wont work.
    : I dont even know if i must use an ADODB or sql or Ole.
    : (dont even know the differences)
    :
    : But if anyone knows the correct code to let things work, please let me know!
    :
    :
    : Thanks,
    :
    : VB Newbie
    :
    :
    :
    :
    :


    Add an ADO data control to your project - set it so it's data source is the mdb in question and then set the datagrids data source to be the ADO Data control - then right click on the datagrid at design time - go to propertys and make sure - allow edit, allow insert, allow delete(if you want them to beble to delete) is checked then you should be able to alter and add data through your data grid.
    [blue]
    C:Dos
    C:Dos Run
    Run Dos Run
    [/blue]

  • : : [b][red]This message was edited by VB Newbie at 2004-6-30 11:24:2[/red][/b][hr]
    : : [b][red]This message was edited by VB Newbie at 2004-6-30 11:22:41[/red][/b][hr]
    : : Hi,
    : :
    : : I have created an access database programaticly.
    : : [code]
    : : Dim cat As ADOX.Catalog
    : : Dim tbl As ADOX.Table
    : :
    : : 'Create NewDB Database.
    : : 'Change the path to the new .mdb file as appropriate. Make sure the folder
    : : 'provided in the path exists. If you path name is not specified, the
    : : 'database will be created in your application folder.
    : : cat = New ADOX.Catalog()
    : : cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
    : : "Data Source=C:AccessDBNewDB.mdb;")
    : : 'Create a new table
    : : tbl = New ADOX.Table()
    : : tbl.Name = "TestTable"
    : : tbl.Columns.Append("Product description")
    : : tbl.Columns.Append("Price")
    : : tbl.Columns.Append("ID", DataTypeEnum.adInteger)
    : : cat.Tables.Append(tbl)
    : : [/code]
    : :
    : : Now I want this to be displayed in a DataGrid so that a user can put his own data into the DataGrid and saves it back to the original Access datafile (NewDB.mdb).
    : :
    : : Simple question: HOW?!!!!!
    : :
    : : I suppose I need an:
    : : - connection
    : : [code]
    : : Dim con As New ADODB.Connection()
    : : [/code]
    : : or:
    : : [code]
    : : Dim con As New SqlClient.SqlConnection("Data Source=C:AccessDBNewDB.mdb")
    : : [/code]
    : : and an adapter:
    : : [code]
    : : Dim DA As New SqlClient.SqlDataAdapter("SELECT Product description, Price, ID FROM TestTable", con)
    : : [/code]
    : : or:
    : : [code]
    : : Dim DA As New OleDb.OleDbDataAdapter("SELECT Product description, Price, ID FROM TestTable", con)
    : : [/code]
    : : and a DataSet:
    : : [code]
    : : Private m_DataSet As DataSet
    : : ' Build the DataSet.
    : : m_DataSet = New DataSet()
    : : Dim dt_students As New DataTable("TestTable")
    : : m_DataSet.Tables.Add(dt_students)
    : : dt_students.Columns.Add("Product description", GetType(String))
    : : dt_students.Columns.Add("Price", GetType(String))
    : : dt_students.Columns.Add("ID", GetType(Integer))
    : :
    : : ' Bind the DataGrid to the DataSet.
    : : DataGrid1.DataSource = m_DataSet
    : : [/code]
    : :
    : : Anyway, it still wont work.
    : : I dont even know if i must use an ADODB or sql or Ole.
    : : (dont even know the differences)
    : :
    : : But if anyone knows the correct code to let things work, please let me know!
    : :
    : :
    : : Thanks,
    : :
    : : VB Newbie
    : :
    : :
    : :
    : :
    : :
    :
    :
    : Add an ADO data control to your project - set it so it's data source is the mdb in question and then set the datagrids data source to be the ADO Data control - then right click on the datagrid at design time - go to propertys and make sure - allow edit, allow insert, allow delete(if you want them to beble to delete) is checked then you should be able to alter and add data through your data grid.
    : [blue]
    : C:Dos
    : C:Dos Run
    : Run Dos Run
    : [/blue]
    :

    That also does not work. Please can you give me a sample code. The code must create an access db with some columns, at a users specified location. Then loads the blank db into a datagrid so that the user can fill the datagrid with data and saves it back to the original access db.

    Thanks,

    VB Newbie

    Thanks,

    Vb Newbie
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories