Next Generation Emulation banner

1 - 4 of 4 Posts

·
Registered
Joined
·
2 Posts
Discussion Starter #1
i have some problem in this coding can any one solve this coding

DataSet ds = new DataSet();
ds = Testimonial.getRandomTestimonials();
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
lblTestimonials.Text = ds.Tables[0].Rows[0]["comments"].ToString();
imgbtnTestim.PostBackUrl = "ReadTestimonial.aspx?id=" + ds.Tables[0].Rows[0]["temp_id"].ToString();
}
else
{
lblTestimonials.Text = "No Testimonial Yet.";
}
}
 

·
Crazy GFX coder
Joined
·
17,133 Posts
i have some problem in this coding can any one solve this coding

DataSet ds = new DataSet();
ds = Testimonial.getRandomTestimonials();
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
lblTestimonials.Text = ds.Tables[0].Rows[0]["comments"].ToString();
imgbtnTestim.PostBackUrl = "ReadTestimonial.aspx?id=" + ds.Tables[0].Rows[0]["temp_id"].ToString();
}
else
{
lblTestimonials.Text = "No Testimonial Yet.";
}
}
you can use the Dataset to fill up a Gridview, combobox etc. and by reading the rows you can even get the values but to my opinion that´s not the best way to get the values from a database..

if you wish to get the values from a database and display them on a textbox or any other control you should do this:

Try
{
Dataset ds = new Dataset();
//Sqlcommand cmd...... setup your command settings and parameters aswell as connection string etc.

//then just make your query.....
cmd.CommandText = "SELECT * FROM mytable";
cmd.Parameters.AddWithValue("@myparameter", myparametervalue); //in case you need parameters...

//now all you have to do is setup your Sqlreader(if you´re working with a sqldatabse) by doing this:

Sqldatareader dr = cmd.ExecuteReader();

//you can use "if" to read a single row or you can use "While" to read more than one like this:

While(dr.read())
{
mytextbox.text = dr.GetString(dr.GetOrdinal("mycolumnName"));
}
dr.Close()
}
catch(exception ex)
{
throw new ArgumentException(ex.message);
}
Finally
{
cmd.Connection.Close()
}

it should work that way but if not just write again here and i´ll help ya.

btw if you´re working with sqldatabases i recommend you to use "SqlTypes" in order to avoid problems when getting "Null" values.

in case you want to edit values when filling the Gridview then you have to use the Gridviews´s "DataRowbound" method to modify each component and value while generating them if you set some controls on your Gridview´s template. in that case you will have to pickup a pointer/reference of the Control in the template and change it as you wish.

Regards
@ruantec
 

·
The Hunter
Joined
·
15,879 Posts
I'm interested to see if you get a response @ruantec, if the good man reads this, I hope he understands that I have removed his signature links since it is pure irrelevant spam.
 
1 - 4 of 4 Posts
Top