Need help working with Ado

Discussion in 'Software' started by personaje, Dec 26, 2008.

  1. personaje

    personaje

    Joined:
    Dec 26, 2008
    Messages:
    2
    I am new to VB, I made a table using ado, but I need to pass the data from a datagrid to the table. The code for the table is like this:


    Dim TableName As String = ""

    'Giving name to the table
    TableName = "Pareo"
    Dim dsStr As String
    Dim dsCn As String
    Dim cnADO As ADODB.Connection
    Dim mdb As ADOX.Catalog
    Dim dt As ADOX.Table




    Try
    mdb = New ADOX.Catalog()
    cnADO = New ADODB.Connection()
    dsStr = My.Settings.DataSource
    dsCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dsStr + ";"
    cnADO.ConnectionString = dsCn
    cnADO.Open()
    mdb.ActiveConnection = cnADO
    'Creating the table
    dt = New ADOX.Table()
    dt.Name = nombreTabla
    dt.Columns.Append("Num", ADOX.DataTypeEnum.adWChar, 5)
    dt.Columns.Append("NI", ADOX.DataTypeEnum.adWChar, 10)
    dt.Columns.Append("Name", ADOX.DataTypeEnum.adWChar, 20)
    dt.Columns.Append("Rnd" & i, ADOX.DataTypeEnum.adWChar, 5)

    dt.Columns.Append("EloBirdInicial", ADOX.DataTypeEnum.adWChar, 10)
    dt.Columns.Append("EloBirdFinal", ADOX.DataTypeEnum.adWChar, 10)
    dt.Keys.Append("PK_NewTable", ADOX.KeyTypeEnum.adKeyPrimary, _
    "NI")

    mdb.Tables.Append(dt)

    Catch ex As Exception MessageBox.Show(ex.Message, "The table was not created") End

    End Try

    MessageBox.Show("The table was created", "Now", MessageBoxButtons.OK)
    End

    I need to pass data form a datagrid to this table, I hope someone can help me
    personaje, Dec 26, 2008
    #1
    1. Advertising

  2. personaje

    marshal

    Joined:
    Dec 29, 2008
    Messages:
    4
    for example
    Code:
    // Create DataTable A
    private DataTable CreateDataTableA()
    {
    DataTable aTable = new DataTable("A");
    DataColumn dtCol;
    DataRow dtRow;
    // Create ID column and add to the DataTable.
    dtCol = new DataColumn();
    dtCol.DataType= System.Type.GetType("System.Int32");
    dtCol.ColumnName = "ID";
    dtCol.AutoIncrement = true;
    dtCol.Caption = "ID";
    dtCol.ReadOnly = true;
    dtCol.Unique = true;
    // Add the column to the DataColumnCollection.
    aTable.Columns.Add(dtCol);
    // Create Name column and add to the table
    dtCol = new DataColumn();
    dtCol.DataType= System.Type.GetType("System.String");
    dtCol.ColumnName = "FName";
    dtCol.AutoIncrement = false;
    dtCol.Caption = "First Name";
    dtCol.ReadOnly = false;
    dtCol.Unique = false;
    aTable.Columns.Add(dtCol);
    // Create Last Name column and add to the table.
    dtCol = new DataColumn();
    dtCol.DataType= System.Type.GetType("System.String");
    dtCol.ColumnName = "LName";
    dtCol.AutoIncrement = false;
    dtCol.Caption = "Last Name";
    dtCol.ReadOnly = false;
    dtCol.Unique = false;
    aTable.Columns.Add(dtCol);
    // Create three rows to the table
    dtRow = aTable.NewRow();
    dtRow["ID"] = 1001;
    dtRow["FName"] = "Mahesh";
    dtRow["LName"] = "Chand" ;
    aTable.Rows.Add(dtRow);
    dtRow = aTable.NewRow();
    dtRow["ID"] = 1002;
    dtRow["FName"] = "Melanie";
    dtRow["LName"] = "Talmadge" ;
    aTable.Rows.Add(dtRow);
    dtRow = aTable.NewRow();
    dtRow["ID"] = 1003;
    dtRow["FName"] = "Vinay";
    dtRow["LName"] = "Bansal" ;
    aTable.Rows.Add(dtRow);
    return aTable;
    }
    // Create DataTable B
    private DataTable CreateDataTableB()
    {
    DataTable bTable = new DataTable("B");
    DataColumn dtCol;
    DataRow dtRow;
    // Create ID column and add to the DataTable.
    dtCol = new DataColumn();
    dtCol.DataType= System.Type.GetType("System.Int32");
    dtCol.ColumnName = "CustomerID";
    dtCol.AutoIncrement = true;
    dtCol.Caption = "CustomerID";
    dtCol.ReadOnly = true;
    dtCol.Unique = true;
    // Add the column to the DataColumnCollection.
    bTable.Columns.Add(dtCol);
    // Create Name column and add to the table
    dtCol = new DataColumn();
    dtCol.DataType= System.Type.GetType("System.String");
    dtCol.ColumnName = "Name";
    dtCol.AutoIncrement = false;
    dtCol.Caption = "Name";
    dtCol.ReadOnly = false;
    dtCol.Unique = false;
    bTable.Columns.Add(dtCol);
    // Create Last Name column and add to the table.
    dtCol = new DataColumn();
    dtCol.DataType= System.Type.GetType("System.String");
    dtCol.ColumnName = "Address";
    dtCol.AutoIncrement = false;
    dtCol.Caption = "Address";
    dtCol.ReadOnly = false;
    dtCol.Unique = false;
    bTable.Columns.Add(dtCol);
    // Create three rows to the table
    dtRow = bTable.NewRow();
    dtRow["CustomerID"] = 11;
    dtRow["Name"] = "Mr. Peter Ferrera";
    dtRow["Address"] = "9th Street, Bank Road, NOIDA" ;
    bTable.Rows.Add(dtRow);
    dtRow = bTable.NewRow();
    dtRow["CustomerID"] = 21;
    dtRow["Name"] = "Ross Tomo";
    dtRow["Address"] = "North Street, Parkway Road, SunCity" ;
    bTable.Rows.Add(dtRow);
    dtRow = bTable.NewRow();
    dtRow["CustomerID"] = 31;
    dtRow["Name"] = "Dr. Jog Rocky";
    dtRow["Address"] = "Turnpike Avenue, Philly" ;
    bTable.Rows.Add(dtRow);
    return bTable;
    }
    
    marshal, Dec 29, 2008
    #2
    1. Advertising

  3. personaje

    personaje

    Joined:
    Dec 26, 2008
    Messages:
    2
    But I have created the table, so I don't need to created again. What I need is to move the data from the grid to the table I have created, but the table is using ado in reference to adox
    personaje, Dec 29, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ramie
    Replies:
    4
    Views:
    1,671
    Guest
    Nov 3, 2003
  2. Guest

    ADO Cursor location - HELP

    Guest, Nov 12, 2003, in forum: MCSD
    Replies:
    3
    Views:
    2,828
    Kline Sphere
    Nov 12, 2003
  3. Irene
    Replies:
    9
    Views:
    2,641
    Kumar Reddi
    Feb 13, 2004
  4. =?Utf-8?B?YWJkb2x5?=

    ado.net

    =?Utf-8?B?YWJkb2x5?=, May 9, 2004, in forum: MCSD
    Replies:
    2
    Views:
    644
    The Poster Formerly Known as Kline Sphere
    May 11, 2004
  5. Rachana

    Need Advice - ado.net 1.x ----> 2.0

    Rachana, Nov 17, 2007, in forum: Computer Support
    Replies:
    1
    Views:
    454
    Mr. Arnold
    Nov 17, 2007
Loading...

Share This Page