PDA

View Full Version : مشکل کلاس و دیتاگرید



phpeproject.ir
جمعه 14 تیر 1392, 20:23 عصر
دوستان چرا این کد کار نمیکنه
این کلاس

public DataSet gridbind(string myQuery)
{
con = new SqlConnection(@"Data Source=WEBENGIN-PC\SQLEXPRESS;Initial Catalog=gold;Integrated Security=True");
adp = new SqlDataAdapter(myQuery, con);
DataSet ds = new DataSet();
adp.Fill(ds);
con.Close();
return ds;
}


اینم کد با فراخوانی کلاس فقط بایند نمیشه


private void frm_goldtype_Load(object sender, EventArgs e)
{
conectionDB myGrid = new conectionDB();

dataGridView1.DataSource = myGrid.gridbind("select * from t_user");
dataGridView1.DataBinds();
}

npscash
یک شنبه 16 تیر 1392, 05:30 صبح
سلام دوست عزیز
میتونی به شکل زیر کدتو تغییر بدی
public DataTable gridbind(string myQuery)
{
SqlConnection con = new SqlConnection(@"Data Source=WEBENGIN-PC\SQLEXPRESS;Initial Catalog=gold;Integrated Security=True");
SqlDataAdapter adp = new SqlDataAdapter(myQuery, con);
DataTable dt = new DataTable();
adp.Fill(dt);
con.Close();
return dt;
}

private void frm_goldtype_Load(object sender, EventArgs e)
{
//conectionDB myGrid = new conectionDB();

dataGridView1.DataSource = gridbind("select * from t_user");
//dataGridView1.DataBinds();
}