Oracle RDB ODBC newbie question

Last post 09-19-2007 8:11 AM by ViagraFalls. 3 replies.

Sort Posts:

  • Oracle RDB ODBC newbie question

    09-19-2007, 7:36 AM
    • Member
      1 point Member
    • rwilson_ie
    • Member since 07-27-2007, 10:18 AM
    • Posts 5

    Hi

    I am trying to extract data from an Oracle RDB database on an Alpha (seems not many / no-one is doing this - or if they are, they aren't putting samples etc up on the Net). I also come from a COBOL/VMS background (no laughing !) with 12 years experience of this and 4 days experience of ASP .NET.

    Anyway, I have figured out how to connect to the database and execute a query - I know I should really use a stored procedure but haven't figured that pout yet.

    How do I get the data from my query into a DataGrid etc ?  I can do it if I set the query in the SQLDataSource and then Bind this to the DataGrid - but how to I do it via code and not use the SqlDataSource ?  My code so far is below :

    Dim myConnection As String

    If myConnection = "" Then

    myConnection = "Dsn=dsnName;server=servername;uid=username;pwd=password;tlo=0;dba=W;svr=svrName;cls=generic;database=attach 'filename l$iv_testdb';xpt=2=tcp/ip;cso=1"

    End If

    Dim myConn As New Data.Odbc.OdbcConnection(myConnection)

    Dim mySelectQuery As String = "SELECT stock, shortname from iv_stocks limit to 10 rows"

    Dim myOdbcCommand As New Data.Odbc.OdbcCommand(mySelectQuery)

    myOdbcCommand.Connection = myConn

    myConn.Open()

    myOdbcCommand.ExecuteNonQuery()

    myOdbcCommand.Connection.Close()

     

    TIA

    Rob

    Filed under: , ,
  • Re: Oracle RDB ODBC newbie question

    09-19-2007, 8:11 AM
    • Participant
      778 point Participant
    • gonzo11
    • Member since 07-02-2007, 4:08 PM
    • Posts 124

    Hello Rob,

     Simplest way to go about populating a GridView in asp.net would be to use a adapter to populate a DataSet. Then you can bind the dataSet to your GridView. Usually in asp.net you want to do that in your Page_Load event.

    Dim myConnection As String

    If myConnection = "" Then

    myConnection = "Dsn=dsnName;server=servername;uid=username;pwd=password;tlo=0;dba=W;svr=svrName;cls=generic;database=attach 'filename l$iv_testdb';xpt=2=tcp/ip;cso=1"

    End If

    Dim myConn As New Data.Odbc.OdbcConnection(myConnection)

    Dim mySelectQuery As String = "SELECT stock, shortname from iv_stocks limit to 10 rows"

    Dim myOdbcCommand As New Data.Odbc.OdbcCommand(mySelectQuery)

    myOdbcCommand.Connection = myConn

    Dim adapter as OdbcDataAdapter = new OdbcDataAdapter(myOdbcCommand);

    Dim ds as DataSet = new DataSet();

    adapter.Fill(ds)

    myGridView.DataSource = ds

    myGridView.DataBind()

    If you google any of the classes used here like (OdbcDataAdapter for example) I am sure that you will find lots of articles on how to populate the data in the grid.

     

    Good luck

    G

  • Re: Oracle RDB ODBC newbie question

    09-19-2007, 8:11 AM
    Answer
    • Participant
      778 point Participant
    • gonzo11
    • Member since 07-02-2007, 4:08 PM
    • Posts 124

    Hello Rob,

     Simplest way to go about populating a GridView in asp.net would be to use a adapter to populate a DataSet. Then you can bind the dataSet to your GridView. Usually in asp.net you want to do that in your Page_Load event. Dim myConnection As String

    If myConnection = "" Then

    myConnection = "Dsn=dsnName;server=servername;uid=username;pwd=password;tlo=0;dba=W;svr=svrName;cls=generic;database=attach 'filename l$iv_testdb';xpt=2=tcp/ip;cso=1"

    End If

    Dim myConn As New Data.Odbc.OdbcConnection(myConnection)

    Dim mySelectQuery As String = "SELECT stock, shortname from iv_stocks limit to 10 rows" Dim myOdbcCommand As New Data.Odbc.OdbcCommand(mySelectQuery)

    myOdbcCommand.Connection = myConn

    Dim adapter as OdbcDataAdapter = new OdbcDataAdapter(myOdbcCommand); Dim ds as DataSet = new DataSet();

    adapter.Fill(ds)

    myGridView.DataSource = ds

    myGridView.DataBind()

    If you google any of the classes used here like (OdbcDataAdapter for example) I am sure that you will find lots of articles on how to populate the data in the grid.

     

    Good luck

    G

  • Re: Oracle RDB ODBC newbie question

    09-19-2007, 8:11 AM
    • Member
      248 point Member
    • ViagraFalls
    • Member since 02-14-2006, 5:18 AM
    • Posts 56

    hi Rob,

     I used SQLServer, but the idea is the same:

    SqlConnection cn = new SqlConnection("Data Source=(local);Initial Catalog=Test;Integrated Security=True");

    DataTable dt = new DataTable();

    SqlDataAdapter da = new SqlDataAdapter("SELECT GETDATE()", cn);

     

    cn.Open();
    da.Fill(dt);
    cn.Close();

    GridView1.DataSource = dt;
    GridView1.DataBind();

     

    HTH

    Peter

Page 1 of 1 (4 items)