Results 1 to 8 of 8

Thread: Retrieving a value from a Dataset

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Question Retrieving a value from a Dataset

    Given a Dataset [ds] which contains 1 row [User in question] and 3 columns [Username, Password, Level].

    I need to store the value of Level [from ds] into a created variable [savedLevel], currently I am trying via this method:
    savedLevel = ds.Tables[Users].Columns[Level]. ?
    Is this the right approach? If so how do I complete the line of code?
    If not can someone help point me in the right direction.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Do something like this :
    Code:
    DataRow MyDataRow =mydataset.Tables[Users].NewRow();
    MyDataRow["Username"]=dr[0].ToString();
    MyDataRow["Password"]=dr[1].ToString();
    MyDataRow["Level"]=dr[2].ToString();
    
    mydataset.Tables[Users].Rows.Add(MyDataRow);
    MyAdapter.Update(mydataset, Users);

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308
    Interresting code but I do not see how it would help, my goal is to get the current value of Level in the Dataset and save it to the variable savedLevel.

    Your code seesm to be updating/adding a row to the Dataset?
    ???

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    sorry , I was a little bit confused . Anyways , it should be like this :

    Code:
    string vari1=dr[0].ToString(); //this would store first row in the first table to this variable . and so on .

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308
    Using the following:
    savedLevel = ds.Tables[0].Columns[3].ToString();

    where Tables[0] = Users; and Column[3] = Level

    This saves the word "Level" into savedLevel and not the actual value. So I assume the table looks like the following

    Table0:
    Row0: UserName Password Level
    Row1: Name Pass 2

    When I do my select and get this record back, I need to store the value "2" in Level to savedLevel variable, not the actual word "Level". How can I accomplish this?

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Code:
    savedLevel = ds.[3].ToString();

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308
    Maybe I am a little confused, but how is that supposed to work?
    There isn't even a definition for the Table.

    C# wont recongnize the syntax you used, the index [3] must be associated to something.

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This is how I use it .
    Code:
    private void LocateData(string TableStr , string ColumnStr ,string	SearchText )
    {
    
    string MyPath=DBSpace.MyClass.GlobalPath;	
    	string MyPassword ="";
    	OleDbConnection MyConnection =new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + MyPath + ";Jet OLEDB:Database Password=" + MyPassword);		
    
    	DataSet ds =new DataSet();
    	string sqlstr = "SELECT * FROM " + TableStr + " WHERE " +ColumnStr + " ='" + SearchText + "'";
    
    MyConnection.Open();
    
    OleDbDataAdapter adp=new OleDbDataAdapter(sqlstr,MyConnection);
    
    adp.Fill(ds,TableStr);
    this.Result_Txt_1.Text = dr[0].ToString();//[1]app name (First row)
    this.Result_Txt_2.Text = dr[1].ToString();//[2]filename(Second row)
    
    MyConnection.Close();
    
    		}

Posting Permissions

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



Click Here to Expand Forum to Full Width