The statement has been terminated.
I create next method:
public bool AddCredit(Guid id, Guid debitorId, int amount, int balance, DateTime date )
{
string query = string.Format("insert into Credits" + "(ID, DebitorID, Amount, Balance, OpenDate)"
+ "values('{0}', '{1}', '{2}', '{3}', '{4}')", id, debitorId, amount, balance, date);
bool flagResult = false;
using (SqlConnection con = new SqlConnection(conectionString))
{
SqlCommand com = new SqlCommand(query, con);
// try
{
con.Open();
if (com.ExecuteNonQuery() == 1)
flagResult = true;
}
//catch
{ }
}
return flagResult;
}
and add parametr in this method
///
/// button new credit
///
///
///
private void btn_addNewCredit_Click(object sender, EventArgs e)
{
if (dall.AddCredit(new Guid(tb_creditID.Text), new Guid(lb_debitorID.SelectedValue.ToString()),
Int32.Parse(tb_creditAmount.Text), Int32.Parse(tb_balance.Text), dtp_date.Value))
this.DialogResult = DialogResult.OK;
else
this.DialogResult = DialogResult.Cancel;
}

raghu v52 reputationPosted Jun 27, 2011, 4:49 AM EDT
try ur function calling statement as follow and try
if (dall.AddCredit(new Guid(tb_creditID.Text), new Guid(lb_debitorID.SelectedValue.ToString()),
Int32.Parse(tb_creditAmount.Text), Int32.Parse(tb_balance.Text), Convert.ToDateTime(dtp_date.value )))
VulpesRank #55 · 29.2K reputationPosted Jun 24, 2011, 12:55 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Jun 27, 2011, 12:16 PM EDT
The second best solution is to use DateTime.ToString("s"), as in:
Pradeep ChandrakerRank #941 · 2.2K reputationPosted Jun 27, 2011, 4:58 PM EDT
If, this is not the case, try using parameterized query as @Sam has suggested.
Suthish NairRank #92 · 22.8K reputationPosted Jun 27, 2011, 9:50 PM EDT
Mike JonsonRank #7,584 · 238 reputationPosted Jun 28, 2011, 12:29 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Jun 28, 2011, 9:04 AM EDT