Professional Web Applications Themes

reading just one cell out of a dataset. - ASP.NET General

Hello, How could I read just one cell out of a dataset? I have a query returing a 3 x 3 table. a b c d e f x y z I need the value of "f" ([2][2] ) from the table. How could I do this using C#? Thanks in advance, System.Data.DataSet onhand(string partno) { string connectionString = "server=\'sql01\'; trusted_connection=true; database=\'data03\'"; System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionStri ng); string queryString = "SELECT [inmast].[fonhand] FROM [inmast] WHERE (([inmast].[fpartno] = \'"+partno+"\') AND" + " ([inmast].[fcstscode] = \'A\'))"; System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand(); dbCommand.CommandText = queryString; dbCommand.Connection = dbConnection; System.Data.IDbDataAdapter dataAdapter = new ...

  1. #1

    Default reading just one cell out of a dataset.


    Hello,


    How could I read just one cell out of a dataset?

    I have a query returing a 3 x 3 table.

    a b c
    d e f
    x y z


    I need the value of "f" ([2][2] ) from the table. How could I do this using
    C#?

    Thanks in advance,



    System.Data.DataSet onhand(string partno) {

    string connectionString = "server=\'sql01\'; trusted_connection=true;
    database=\'data03\'";

    System.Data.IDbConnection dbConnection = new
    System.Data.SqlClient.SqlConnection(connectionStri ng);

    string queryString = "SELECT [inmast].[fonhand] FROM [inmast] WHERE
    (([inmast].[fpartno] = \'"+partno+"\') AND" + " ([inmast].[fcstscode] =
    \'A\'))";

    System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();

    dbCommand.CommandText = queryString; dbCommand.Connection = dbConnection;

    System.Data.IDbDataAdapter dataAdapter = new
    System.Data.SqlClient.SqlDataAdapter();

    dataAdapter.SelectCommand = dbCommand; System.Data.DataSet dataSet = new
    System.Data.DataSet();
    dataAdapter.Fill(dataSet);
    return dataSet;
    }


    N. Okan Guney Guest

  2. #2

    Default Re: reading just one cell out of a dataset.

    DataSet.Tables("TableName").Rows(1)(2)

    Where Rows(Zero Based Row Number Index)(Zero Based Column Index)

    Or Rows(1)("ColumnNameAsString")

    Hope this helps.

    Justin


    "N. Okan Guney" <guneyn74> wrote in message
    news:%23P$U5vkSDHA.1912TK2MSFTNGP12.phx.gbl...
    >
    > Hello,
    >
    >
    > How could I read just one cell out of a dataset?
    >
    > I have a query returing a 3 x 3 table.
    >
    > a b c
    > d e f
    > x y z
    >
    >
    > I need the value of "f" ([2][2] ) from the table. How could I do this
    using
    > C#?
    >
    > Thanks in advance,
    >
    >
    >
    > System.Data.DataSet onhand(string partno) {
    >
    > string connectionString = "server=\'sql01\'; trusted_connection=true;
    > database=\'data03\'";
    >
    > System.Data.IDbConnection dbConnection = new
    > System.Data.SqlClient.SqlConnection(connectionStri ng);
    >
    > string queryString = "SELECT [inmast].[fonhand] FROM [inmast] WHERE
    > (([inmast].[fpartno] = \'"+partno+"\') AND" + " ([inmast].[fcstscode] =
    > \'A\'))";
    >
    > System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
    >
    > dbCommand.CommandText = queryString; dbCommand.Connection = dbConnection;
    >
    > System.Data.IDbDataAdapter dataAdapter = new
    > System.Data.SqlClient.SqlDataAdapter();
    >
    > dataAdapter.SelectCommand = dbCommand; System.Data.DataSet dataSet = new
    > System.Data.DataSet();
    > dataAdapter.Fill(dataSet);
    > return dataSet;
    > }
    >
    >

    S. Justin Gengo Guest

  3. #3

    Default reading just one cell out of a dataset.

    Try this:

    F_Value = dataset.Tables[0].Rows[1].ItemArray[5];

    Or

    F_Value = dataset.Tables[0].Rows[1]["FieldNameForF"];

    You may have to cast the value to the correct datatype,
    but this should get you started.

    HTH,

    Jeff Ptak

    >-----Original Message-----
    >
    >Hello,
    >
    >
    >How could I read just one cell out of a dataset?
    >
    >I have a query returing a 3 x 3 table.
    >
    >a b c
    >d e f
    >x y z
    >
    >
    >I need the value of "f" ([2][2] ) from the table. How
    could I do this using
    >C#?
    >
    >Thanks in advance,
    >
    >
    >
    >System.Data.DataSet onhand(string partno) {
    >
    >string connectionString = "server=\'sql01\';
    trusted_connection=true;
    >database=\'data03\'";
    >
    >System.Data.IDbConnection dbConnection = new
    >System.Data.SqlClient.SqlConnection(connectionStr ing);
    >
    >string queryString = "SELECT [inmast].[fonhand] FROM
    [inmast] WHERE
    >(([inmast].[fpartno] = \'"+partno+"\') AND" + " ([inmast].
    [fcstscode] =
    >\'A\'))";
    >
    >System.Data.IDbCommand dbCommand = new
    System.Data.SqlClient.SqlCommand();
    >
    >dbCommand.CommandText = queryString; dbCommand.Connection
    = dbConnection;
    >
    >System.Data.IDbDataAdapter dataAdapter = new
    >System.Data.SqlClient.SqlDataAdapter();
    >
    >dataAdapter.SelectCommand = dbCommand;
    System.Data.DataSet dataSet = new
    >System.Data.DataSet();
    >dataAdapter.Fill(dataSet);
    >return dataSet;
    >}
    >
    >
    >.
    >
    Jeff Ptak Guest

Similar Threads

  1. Question how to assign from one cell to other cell in report builder
    By pengleang in forum Brainstorming Area
    Replies: 0
    Last Post: December 1st, 10:07 AM
  2. Reading XML into a DataSet
    By Dana Pellerin in forum Macromedia Flash Data Integration
    Replies: 1
    Last Post: January 11th, 07:59 PM
  3. Replies: 1
    Last Post: February 17th, 09:37 PM
  4. Replies: 3
    Last Post: April 30th, 12:19 AM
  5. Replies: 1
    Last Post: December 6th, 01:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139