【发布时间】:2012-01-29 07:02:19
【问题描述】:
我已经走到了尽头……
我正在从 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# 非常缺乏经验,所以任何答案都将不胜感激。
请帮忙。
谢谢,
子目录
【问题讨论】:
标签: c# sql datagridview