|
-
Aug 11th, 2003, 09:09 AM
#1
Thread Starter
Hyperactive Member
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.
-
Aug 11th, 2003, 10:18 AM
#2
Sleep mode
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);
-
Aug 11th, 2003, 10:51 AM
#3
Thread Starter
Hyperactive Member
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?
???
-
Aug 11th, 2003, 10:58 AM
#4
Sleep mode
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 .
-
Aug 11th, 2003, 11:11 AM
#5
Thread Starter
Hyperactive Member
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?
-
Aug 11th, 2003, 11:17 AM
#6
Sleep mode
Code:
savedLevel = ds.[3].ToString();
-
Aug 11th, 2003, 11:22 AM
#7
Thread Starter
Hyperactive Member
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.
-
Aug 11th, 2003, 11:43 AM
#8
Sleep mode
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|