problem to retrieve an info in a sql request / problème pour recéper une info dans une requête sql
-
Don't send it, I won't look at it. I don't have time to be a mentor to anyone - and I get a couple of request for it a month, and certainly couldn't do it for everyone who asks: so I don't do it at all to be as fair as I can to everybody.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
hello sir all my apologies for the delay ... i was putting my code clean as you advised me. I have an error like microsoft jet engine
try
{
setConnection();
sql_con.Open();
using (sql_cmd = sql_con.CreateCommand())
{
string txtQuery = "INSERT INTO Detail_temp (ref_det, qute_det, Designation, Prix_unitaire_HT, Prix_total_HT) VALUES (@ref_det,@qute_det,@Designation,@Prix_unitaire_HT,@Prix_total_HT)";
sql_cmd.Parameters.AddWithValue("@ref_det", TxtRefProduit.Text);
sql_cmd.Parameters.AddWithValue("@qute_det", TxtQteCmd.Text);
sql_cmd.Parameters.AddWithValue("@Designation", TxtDesignation.Text);
sql_cmd.Parameters.AddWithValue("@Prix_unitaire_HT", TxtPrixUnitaire.Text);
sql_cmd.Parameters.AddWithValue("@Prix_total_HT", total);
sql_cmd = new OleDbCommand(txtQuery, sql_con);
sql_cmd.ExecuteNonQuery();
//ExecuteQuery(txtQuery);
}
}
catch(OleDbException ex)
{
MessageBox.Show(ex.Source);
}Hi, please stop doing
catch(OleDbException ex)
{
MessageBox.Show(ex.Source);
}instead do
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}It will (1) be able to catch more problems, and (2) will provide much more information when something goes wrong (including the exact line number when running in Visual Studio); you may not understand all of its output right away, but that typically is the info one needs to easily pinpoint what went wrong. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Hi, please stop doing
catch(OleDbException ex)
{
MessageBox.Show(ex.Source);
}instead do
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}It will (1) be able to catch more problems, and (2) will provide much more information when something goes wrong (including the exact line number when running in Visual Studio); you may not understand all of its output right away, but that typically is the info one needs to easily pinpoint what went wrong. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Hello sir and thank you for the info, I think I saw it when I was doing my research. And it was written only to see the problems with connection to the database. So I would like to know if we could use it only at the connection of the database or not?
All exceptions derive from the Exception class, so catching Exception will catch "everything". Whatever your code is about, it is most often wise to put it inside a try-catch block that catches and displays all information about all exceptions. And when your code misbehaves and you don't yet have a try-catch, adding one is the first thing you should do. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
All exceptions derive from the Exception class, so catching Exception will catch "everything". Whatever your code is about, it is most often wise to put it inside a try-catch block that catches and displays all information about all exceptions. And when your code misbehaves and you don't yet have a try-catch, adding one is the first thing you should do. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum