I want to add date from
DateTimePicker to database table & also want to retrieve date from
database table to DateTimePicker.
Basically,My datagridview get updated at each operation(insert,update,delete) & it has edit button. when I click on edit button all the values from datagridview row are set to the controls in my form(label,textbox) correspondingly.
Main form code :
private void btnSAdd_Click(object sender, EventArgs e)
{
SavingsDetails sd = new SavingsDetails(lblSTId.Text,cmbSGID,cmbSMId,dtpInstallmentDate.Text,txtInstallmentAmt.Text);
sd.Add();
setSavingsGridView();
}
code in SavingsDetails Class :
class SavingsDetails
{
protected int STId,MId,GId,Amt;
DateTime SDate;
Connection con;
public SavingsDetails(string _STId, int _GId, int _MId, DateTime _SDate, string _Amt)
{
con = new Connection();
STId = Convert.ToInt16(_STId);
GId = _GId;
MId = _MId;
SDate = _SDate;
Amt = Convert.ToInt32(_Amt);
}
public void Add()
{
con.Execute("insert into tblSavingsDetails(STId,STDate,GId,MId,SavingInstallment) values("+ STId +","+ SDate +","+ GId +","+ MId +","+ Amt +"");
}
To retrieve from database to form controls :
private void dgvSavingsDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
btnSUpdate.Enabled = true;
lblSTId.Text = dgvSavingsDetails.Rows[e.RowIndex].Cells[2].Value.ToString();
cmbSGrpName.SelectedValue = dgvSavingsDetails.Rows[e.RowIndex].Cells[3].Value;
cmbSMName.SelectedValue = dgvSavingsDetails.Rows[e.RowIndex].Cells[4].Value;
dtpInstallmentDate.Text = dgvSavingsDetails.Rows[e.RowIndex].Cells[5].Value.ToString();
txtInstallmentAmt.Text = dgvSavingsDetails.Rows[e.RowIndex].Cells[6].Value.ToString();
}
else if (e.ColumnIndex == 1)
{
}
}
Please Help.