[RESOLVED] Easy data view syntax question
Code:
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
DataView dv = new DataView();
da.SelectCommand = propertiesCmd;
da.Fill(ds, "Solution Properties");
dv = ds.Tables["Solution Properties"].DefaultView;
dv.RowFilter = "[type key] = '-1689071302'";
String propertyStr = dv.Table.Columns["Value"].ToString();
All I want to do is get the data from a filtered data view in a string. See the last two lines of code. Thats what Im trying but propertyStr="Value". "Value" is the name of the column whos data I want. propertyStr should be something from my dataview, not just the title of the column. Whats the correct syntax to accomplish this.
Re: Easy data view syntax question
This:
Code:
String propertyStr = dv.Table.Columns["Value"].ToString();
is specifically getting a column from the table. That's not what you want. First of all you have to get a row, then you have to get the value from that row that is in the column you want. There's no need to go via the table for this because the view exposes the row itself, e.g.
vb.net Code:
For Each row As DataRowView in dv
MessageBox.Show(row("Value").ToString())
Next row
That will get the value from the row in the column named "Value".
Re: Easy data view syntax question
Code:
dv.RowFilter = "[type key] = '-1689071302'";
string propertyStr = dv[0].Row[0].ToString();
Re: Easy data view syntax question
Oops. Forgot I was in C# land:
Code:
foreach (DataRowView row in dv)
{
MessageBox.Show(row["Value"].ToString());
}
Re: Easy data view syntax question
Quote:
Originally Posted by mar_zim
Code:
dv.RowFilter = "[type key] = '-1689071302'";
string propertyStr = dv[0].Row[0].ToString();
this worked for me perfectly. Thanks!
Re: [RESOLVED] Easy data view syntax question
Like I said, there's no need to go via the DataRow when the DataRowView exposes the same data. This:
Code:
string propertyStr = dv[0].Row[0].ToString();
does the same as this:
Code:
string propertyStr = dv[0][0].ToString();
Re: [RESOLVED] Easy data view syntax question
Quote:
Originally Posted by jmcilhinney
Like I said, there's no need to go via the DataRow when the DataRowView exposes the same data. This:
Code:
string propertyStr = dv[0].Row[0].ToString();
does the same as this:
Code:
string propertyStr = dv[0][0].ToString();
i see what your saying. very good. thanks.