Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.Data.DataRowView"

Status
Not open for further replies.

nowayout

Programmer
Feb 25, 2003
364
US
Hi all,

Sorry to post again!!! i am getting this in database instead of selected values from combobox. the value i am gettting is "System.Data.DataRowView". What is the solutiong for this? i tried to find out but not successful so far!!

Thanks
 
That happens when you are using a DataView as DataSource and the DisplayMember is not defined in the DataView.
cbx.DataSource = dtView;
cbx.DisplayMember="mycolumn";
"mycolumn" is not case sensitive and I hope it does not contain spaces.
The "mycolumn" must exist in the dtView object.
You can see that in debugger by inspecting the dtView object or check the RowFilter if you construct it using a RowFilter.
-obislavu-
 
how can i check that but as far as that goes i think i did it right!!! check this

DataSet ds1 = new DataSet("test2");
SqlDataAdapter da1 = new SqlDataAdapter("select * from testtable", oConn1);


da1.Fill(ds1,"mg1");

DataTable dt1 = ds1.Tables["mg1"];

Failuresymp.DataSource = dt1;

Failuresymp.DisplayMember = "Symptoms";
 
Put a breakpoint after :
Failuresymp.DataSource = dt1;
Now drag the dt1 object in the debug window and iterate through Columns.List and see how many columns you retrive (should be all because SELECT *) and if see if the "Symptoms" columns is present.
If you see that column then your combobox must be populated with data from the dt1 object.
If the problem persists then tell me where you put the about code in your application.
obislavu
 
the combobox does get populate with the right data but when i have inserti n to different table the value which is selected in this combobox is appear as system.data.datarowview in database table!!
 
This is another problem and show the code you are using to insert!
-obislavu-
 
string q3 = "insert into failure_report(job_number, Asset_no, component_des, failure_symp, sub_assembly) VALUES ('" + jobnumber.Text.ToString().Trim() + "','" + AssetNumber.Text.ToString().Trim() + "','" + compdes.Text.ToString().Trim() + "', '" + Failuresymp.SelectedItem.ToString().Trim()+ "', '" + SubAssembly.SelectedItem.ToString().Trim()+ "' )";


failure_symp datafield is varchar;
 
Now, there is a raison for what you got.
You can see in the following lines:

Code:
da1.Fill(ds1,"mg1");

DataTable dt1 = ds1.Tables["mg1"];

Failuresymp.DataSource = dt1;

Failuresymp.DisplayMember = "Symptoms";

Whre you need to retrive the selected item:
Code:
DataRowView item = (DataRowView)Failuresymp.SelectedItem;
if (item !=null)
{
	//string selectedvaluemember = item["valuemembercolumn"].ToString(); you do not use valuemember
	string selecteddisplaymemeber = item["Symptoms"].ToString().Trim();
}
That is all!
-obislavu-
 
by doing that the combobox populated with System.Data.DataRowView but the thing is if puplate with right values in list but only thing is when i try to insert that values in database the values i get in database is System.Data.DataRowView, instead of selected value....
 
Doing that Failuresymp.DataSource = dt1;
The items in the Failuresymp combobox are objects of DataRowView type but in the combobox you should see the values from the dt1.Rows["Symptoms"] where i =0...dt1.Rows.Count;
Next before you build the INSERT statements add the code that I post before.
Do the same for other combobox controls that you need to retrieve the selected string, let say selectedSubAssembly
You should have like here exactly where you build the INSERT statement.
[code
DataRowView item = (DataRowView)Failuresymp.SelectedItem;
if (item !=null)
{
string selectedSymptom = item["Symptoms"].ToString().Trim();
}
item = (DataRowView)SubAssembly.SelectedItem;
if (item !=null)
{
string selectedSubAssembly = item["SubAssembly"].ToString().Trim();
}

string q3 = "insert into failure_report(job_number, Asset_no, component_des, failure_symp, sub_assembly) VALUES ('" + jobnumber.Text.ToString().Trim() + "','" + AssetNumber.Text.ToString().Trim() + "','" + compdes.Text.ToString().Trim() + "', '" + selectedSymptom + "', '" + selectedSubAssembly + "' )";
[/code]

obislavu
 
getting error saying that The name 'selectedSymptom' does not exist in the class or namespace 'WindowsApplication4.failurereport'
 
Declare the vars in the right scope.
Take a look here!
[code
string selectedSymptom ="";
string selectedSubAssembly ="":
DataRowView item = (DataRowView)Failuresymp.SelectedItem;
if (item !=null)
{
selectedSymptom = item["Symptoms"].ToString().Trim();
}
item = (DataRowView)SubAssembly.SelectedItem;
if (item !=null)
{
selectedSubAssembly = item["SubAssembly"].ToString().Trim();
}

string q3 = "insert into failure_report(job_number, Asset_no, component_des, failure_symp, sub_assembly) VALUES ('" + jobnumber.Text.ToString().Trim() + "','" + AssetNumber.Text.ToString().Trim() + "','" + compdes.Text.ToString().Trim() + "', '" + selectedSymptom + "', '" + selectedSubAssembly + "' )";
[/code]

obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top