1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection con= new SqlConnection("Data Source=NICOLAS;" +
"Initial Catalog=Northwind;Integrated Security=SSPI");
try
{
SqlCommand com= new SqlCommand("OrdersByDate",con);
com.CommandType=CommandType.StoredProcedure;
com.Parameters.Add("@StartDate",SqlDbType.DateTime).Value=
new DateTime(1997,1,1);
com.Parameters.Add("@EndDate",SqlDbType.DateTime).Value=
new DateTime(1997,1,1);
SqlDataAdapter DA= new SqlDataAdapter(com);
DataSet dt=new DataSet("Orders");
DA.Fill(dt,"OrdersByDate");
dataGrid1.SetDataBinding(dt,"OrdersByDate");
}
catch(Exception ex)
{
MessageBox.Show(this,ex.Message,"Erreur",MessageBoxButtons.OK);
}
} |
Partager