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 vPosted Jun 27, 2011, 8:49 AM
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 )))
Suthish NairPosted Jun 28, 2011, 1:04 PM
Mike JonsonPosted Jun 28, 2011, 4:29 AM
Suthish NairPosted Jun 28, 2011, 1:50 AM
Pradeep ChandrakerPosted Jun 27, 2011, 8:58 PM
If, this is not the case, try using parameterized query as @Sam has suggested.
Sam HobbsPosted Jun 27, 2011, 4:16 PM
The second best solution is to use DateTime.ToString("s"), as in:
VulpesPosted Jun 24, 2011, 4:55 AM