reading just one cell out of a dataset.

Ask a Question related to ASP.NET General, Design and Development.

  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. Similar Questions and Discussions

    1. Reading XML into a DataSet
      Ok, I posted this before, but I'm going to restate my question in order to hopefully make it clearer. I have the following XML: <?xml...
    2. How to set cell background based on cell value when datagrid is displayed
      I would like to check a datagrid cell value, and change the color of the cell background, when a datagrid is displayed. I want to do this as early...
    3. I need to have a tooltip appear over a cell showing data from another cell in the same row.
      I have a datagrid with locations from around the world. In hidden cells, I have the Lat and Long of that location. I need to be able to mouseover...
    4. RadioButtonList In A DataGrid Cell - Can I find the selected button without editing the cell?
      I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a...
    5. update row with null numeric or datetime dataset cell values in a datagrid
      I keep getting the, now, dreaded "System.FormatException: String was not recognized as a valid DateTime" error when updating a datagrid row that has...
  3. #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@yahoo.com> wrote in message
    news:%23P$U5vkSDHA.1912@TK2MSFTNGP12.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

  4. #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

Posting Permissions

  • You may not post new threads
  • You may 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