Click to See Complete Forum and Search --> : DataSource and GridView
minnie_lanus
January 15th, 2008, 07:29 AM
Hi, I want to fill an empty GridView with some data, here is my code:
con.consulta = "select * from moviles where id = 3";
con.CreateCon();
DataSet myDataSet = new DataSet();
myDataSet = con.data_set;
GridView1.DataSource = myDataSet.Tables[0];
When I run the site, I donīt have anything on gridview1, it is empty like when I begin. Somebody can help me?
Thanks,
Vanesa.
PeejAvery
January 15th, 2008, 08:02 AM
Is CreateCon() your own created function? Without seeing the code for that, we can't exactly tell you why it isn't populating. It could be the connection to the database, or many other things.
minnie_lanus
January 15th, 2008, 08:05 AM
Is CreateCon() your own created function? Without seeing the code for that, we can't exactly tell you why it isn't populating. It could be the connection to the database, or many other things.
Yes, i made that function. Here is the class:
public class Conexion
{
//public string strCon;
private static string strCon = "Provider=SQLOLEDB;Server=GUCCIONE\\SQLEXPRESS;Database=pruebas;Integrated Security=SSPI;Persist Security Info=False";
public string consulta;
public DataSet data_set;
public string error;
public bool CreateCon()
{
data_set = new DataSet();
OleDbConnection myAccessConn = null;
try
{
myAccessConn = new OleDbConnection(strCon);
}
catch (Exception ex)
{
Console.Write(ex.Message);
error = ex.Message;
return false;
}
try
{
OleDbCommand myAccessCommand = new OleDbCommand(consulta, myAccessConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
myAccessConn.Open();
myDataAdapter.Fill(data_set);
}
catch (Exception ex)
{
Console.Write(ex.Message);
error = ex.Message;
return false;
}
finally
{
myAccessConn.Close();
}
return true;
}
}
Can you help me?
aamador
January 21st, 2008, 08:10 PM
Add one more statement
GridView1.Databind()
That will do it. Assuming your data access works
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.