dataset

  • Thread starter Thread starter juli jul
  • Start date Start date
J

juli jul

Hello,I am trying to retrieve a column from a dataset which will be in
array as a collection of strings.
I am doing something like that:

ds = new DataSet();
Adapter1.Fill(ds);
MessageBox.Show(ds.Tables["n"].Columns["p"].ToString());

but it's not working (it gives the :Object reference not set to an
instance of an object.)
why? how can I do it?
Thanks a lot!
 
You mean something as this one?

MessageBox.Show(ds.Tables["n"].Columns["p"].ColumnName.ToString());

Or something else, this is a little bit strange sentence because this shoud
give "p".

Cor
 
Hi,

Check the Tables property of database. Check whether the table named "n" is
present there.
If that table is present check whether column named "p" is present Columns
property of that table.

It gives "Object reference not set to an instance of an object." as it is
not getting one of the two things,

Hope this helps.

Regards,
Reshma
 
Juli,

The columns describes the items

The items self you get with
MessageBox.Show(ds.Tables["n"].Rows[x]["p"].ToString());

where "Item: is default it is official
MessageBox.Show(ds.Tables["n"].Rows[x].Item["p"].ToString());

I hope his helps

Cor
 
Thanks it is but I have another question refering to it:
I am doing the :

this.comboBox1.DataBindings.Add("SelectedValue",ds.Tables[0].Rows["na
me"],"sysobjects.name");

and get this error:
An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll

Additional information: This would cause two bindings in the collection
to bind to the same property.

Why and how to solve this?
Thanks!
 
Juli,

Because you have to bind it to the table not to the rows, that is affected
by the currencymanager a sample

this.textBox1.DataBindings.Add("Text",ds.Tables[0],"name");

However what you do will never go. For that is not the databindings

You probably want to set the
combobox1.SelectedIndex = Integer;

Cor
 
Hello,
I have a dataset ,it contains a table with one column named "name" - I
want to add all the rows under this column(each one of the a string) to
a combobox as a source.
How can I do that?
Thanks a lot!
 
Juli

combobox1.DataSource = ds.tables[0];
combobox1.DisplayMember = "name"

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top