Norm,
First a few general comments about your code -
You are using string concatenation to create the command, that is probably
not a great idea. You should use parameterized queries, and stringbuilder to
concatenate (if need be).
Okay secondly, your query is "Select * ... ", it's probably a better idea to
specify the column names.
Finally, answering your question
,
I am trying to use this code to select a particular record using the fill
method. is there a way to do this?? Please help me someone.
There are numerous ways to do this, and the specific way you pick depends on
your specific situation,
a) You can limit the specific row you need in the database, using a where
clause in front of your SQL Query.
b) You can sue SqlDataReader, which is the return value of
SqlCommand.ExecuteReader, remember to close the data reader and connection
when you are done.
c) You can use a dataset/datatable and then limit the specific row you want
using the DataTable.Select method
d) You can use a dataset/datatable, and then create a dataview on the
datatable, and limit your results to the specific row/s you are interested
in, using the dataview.
Each of these have their own plusses and minuses, and the specific approach
you may take, depends on your situation/usage.
- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
nbohana said:
I am trying to use this code to select a particular record using the fill
method. is there a way to do this?? Please help me someone.
SqlCommand cmd = new SqlCommand("SELECT * " + "FROM [animal-info]",
cnKennel);
da = new SqlDataAdapter(cmd);
cbd = new SqlCommandBuilder(da);
dsPictures = new DataSet();
da.Fill(dsPictures);
lstPictures.DataSource = dsPictures.Tables[0];
lstPictures.DisplayMember = "filename";