ببخشید کدمربوط به دیتاکرید درخودبرنامه
کد HTML:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyTest
{
public partial class Form1 : Form
{
private SqlConnection SqlCon;
private SqlCommand SqlCmd;
private SqlDataAdapter SqlDA;
private DataTable DTable;
private long Id;
private long Cal;
public Form1()
{
InitializeComponent();
}
private void Binding()
{
//try
//{
//DateTime dt = Convert.ToDateTime(FarsiLibrary.Utils.PersianDateC onverter.ToPersianDate(DateEtebar22.SelectedDateTi me));
SqlCon = new SqlConnection();
SqlCon.ConnectionString = MyTest.Properties.Settings.Default.MyTestConnectio nString;
SqlCon.Open();
SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandType = CommandType.Text;
SqlCmd.CommandText = "SELECT *FROM MyDate"; //WHERE (ID=@Id)";
//SqlCmd.Parameters.Add("@Id", SqlDbType.BigInt).Value = Id;
SqlDA = new SqlDataAdapter();
SqlDA.SelectCommand = SqlCmd;
SqlCmd.ExecuteNonQuery();
DTable = new DataTable();
SqlDA.Fill(DTable);
dataGridView1.DataSource = DTable;
// SqlCon.Close();
//dataGridView1.Rows.Clear();
//if (DTable.Rows.Count > 0)
//{
// FarsiLibrary.Utils.PersianDate p1, p2;
// DataRow[] Drows = new DataRow[DTable.Rows.Count];
// DTable.Rows.CopyTo(Drows, 0);
// for (int i = 0; i < Drows.Length - 1; i++)
// {
// for (int j = i + 1; j < Drows.Length; j++)
// {
// p1 = FarsiLibrary.Utils.PersianDateConverter.ToPersianD ate((DateTime)Drows[i].ItemArray[6]);
// p2 = FarsiLibrary.Utils.PersianDateConverter.ToPersianD ate((DateTime)Drows[j].ItemArray[6]);
// if (p1 > p2)
// {
// DataRow dr;
// dr = Drows[i];
// Drows[i] = Drows[j];
// Drows[j] = dr;
// }
// }
// }
// for (int j = 0; j < Drows.Length; j++)
// {
// DateTime Persian = FarsiLibrary.Utils.PersianDateConverter.ToPersianD ate((DateTime)Drows[j].ItemArray[6]);
// if (Persian >= DateEtebar22.SelectedDateTime)
// {
// if ((byte)Drows[j].ItemArray[4] == 1)
// {
// Cal += (long)Drows[j].ItemArray[8];
// dataGridView1.Rows.Add(++counter, Persian, Drows[j].ItemArray[1], Drows[j].ItemArray[1]
// , 0, Drows[j].ItemArray[8], Cal);
// }
/*if (((byte)Drows[j].ItemArray[4] == 3) || ((byte)Drows[j].ItemArray[4] == 4))
{
Cal -= (long)Drows[j].ItemArray[8];
dataGridView1.Rows.Add(++counter, Persian, Drows[j].ItemArray[2], Drows[j].ItemArray[5]
, Drows[j].ItemArray[8], 0, Cal);
}*/
//}
SqlCon.Close();
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
//finally
//{
// SqlCon.Close();
//}
}
private void Form1_Load(object sender, EventArgs e)
{
Binding();
}
}
}