cool disel
01-27-2009, 08:39 AM
hi i'm a new web developer and i was wondering what's wrong with this code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from [UserTable]");
// creating the data adapter
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = cmd;
//creating datasets
DataSet DS = new DataSet();
DA.Fill(DS, "UserTable");
// creating data view
DataView DV = new DataView();
//creating data table
DataTable DT = new DataTable();
//PagedDataSource PDS = new PagedDataSource();
GridView1.DataSource = DA;
con.Close();
}
}
it gives an error
"Fill: SelectCommand.Connection property has not been initialized."
in this line
DA.Fill(DS, "UserTable");
thanx :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from [UserTable]");
// creating the data adapter
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = cmd;
//creating datasets
DataSet DS = new DataSet();
DA.Fill(DS, "UserTable");
// creating data view
DataView DV = new DataView();
//creating data table
DataTable DT = new DataTable();
//PagedDataSource PDS = new PagedDataSource();
GridView1.DataSource = DA;
con.Close();
}
}
it gives an error
"Fill: SelectCommand.Connection property has not been initialized."
in this line
DA.Fill(DS, "UserTable");
thanx :)