You must Sign In to post a response.
  • Category: .NET

    how to access the data in a last row of a column

    The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    using the query "select last(<columnname>) from <tablename>" i can find the value in the last row of a column.
    but my question is ; i have to display this value in a messagebox, how to assign the value retrieved from this query to a string variable?
  • #275
    Hi Shruthi,
    Get the query output as dataset and then from that dataset we can get the values as shown below.

    Dim DS As DataSet
    DS = Query Output

    Dim Ls As String = DS.Tables(0).Rows(0).Item(0)
    (or)
    Dim Ls As String = DS.Tables(0).Rows(0).Item("EmpName")

    Thanks and Regards,
    J.Kasiviswanath

  • #278
    Hi,

    If u expect a single value from the query, u can very much use the ExecuteScalar method of Command object, rather than going for dataset , datatable and finding the rows and columns.

    string strValue = cmd.ExecuteScalar();
    MessageBox.Show(strValue);

    This Query basically gets u the data in the first row of the first column, in the result ,so if ur sure that the data fetched is having only single value. use this.

    Tats it.

    Cheers!
    John

  • #188303
    Hi Dear Shruthi,

    Try this coding...

    Dim Ds as new Dataset
    Dim Da as new OledbDataAdapter
    Dim Str_Value As String

    Da = New OledbDataAdapter(Query,ConnectionString)
    Da.Fill(Ds,"Table1")

    If Ds.Tables("Table1").Rows.Count > 0 Then

    Str_Value=Ds.Tables("Table1").Rows(0).Item("Field_Name").ToString


    By,
    Shabeer.


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.