PDA

View Full Version : سوال: bind the Datagrid



zeinab-es'haghi
دوشنبه 17 مرداد 1390, 14:19 عصر
من یک کد VB برای تخصیص داده به گرید ویو پیداکردم :
Sub BindGrid()
Dim SQL As String = "SELECT OrderID,
ShipName, ShipCountry, ShipVia FROM Orders"
Dim DA As SqlDataAdapter = New SqlDataAdapter(SQL, ConnStr)
Dim DS As New DataSet
DA.Fill(DS, "Orders")
DataGrid1.DataSource = DS.Tables("Orders").DefaultView
DataGrid1.DataBind()
End Sub
اما وقتی به c# می نویسمش تو قسمت ada.fill این ارور رو میده:
The SelectCommand property has not been initialized before calling 'Fill'.

کد c#اینه:
static SqlConnection cnc = new SqlConnection();
static SqlCommand cmd = new SqlCommand();
static SqlDataReader dr;
SqlDataAdapter ada = new SqlDataAdapter();
DataSet dset = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
cnc.ConnectionString = "Server=RAZIEH-PC ;User=Id; ;DataBase=mydb1; Integrated Security=True";
cmd.Connection = cnc;
cnc.Open();
cmd.CommandText = "select productName from Product";
dr = cmd.ExecuteReader();
ada.Fill(dset,"Product");
DataGrid1.DataSource = dset.Tables;
DataGrid1.DataBind();}


کسی دلیلش رو می دونه؟