我在繩子的一端創建的DataGridView ...在運行時
我正在從dateTimePicker的價值,我根據來自dateTimePicker的值執行一個SQL查詢。查詢的結果應該在執行查詢後顯示在Datagridview上。
這是迄今爲止我所做的代碼:
namespace App1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DateTime varDate;
varDate = dateTimePicker1.Value;
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=SUBASH-LAPTOP\COBRA;Initial Catalog=Test;Integrated Security=True");
SqlCommand Command = con.CreateCommand();
Command.CommandText = "Select * From orders where date_purchased <= @varDate ";
con.Open();
SqlDataReader reader = Command.ExecuteReader();
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add();
DataGridView d1 = new DataGridView();
this.Controls.Add(d1);
while (reader.Read())
{
d1.DataSource = ds.Tables[0];
}
}
}
我用C#很缺乏經驗,所以任何答案會很感激。
請幫忙。
感謝,
Subash
感謝您的鏈接有...它幫助了我很多 – Subash 2011-12-28 17:23:50
如果你喜歡的答案;請將其投票,以便其他人也可以看到鏈接! – DevinBM 2011-12-30 16:30:35