problem to make a second recording
-
the goal is to add and save later I can do it once when I want to do it for a second time I have an error: unable to find table 0, I must close the form and open it again so that I can do another one ... how to solve this problem without closing my form before?
private void BtnAjouter_Click(object sender, EventArgs e)
{
int total;
decimal total_achat;
//si les champs sont vides
if (TxtDesignation.Text == "" || TxtPrixUnitaire.Text == "" || TxtQteCmd.Text == "" || TxtQteStock.Text == "" || TxtRefProduit.Text == "")
{
MessageBox.Show("Rassurez vous que tous les champs ont bien été rempli.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
//Vérifier si la valeur saisie est numeric
if (Int32.TryParse(TxtQteCmd.Text, out int value) && TxtRefProduit.Text != "")
{
//Vérifier si la commande est inferieur ou egale au stock
int a = 0;
int b = 0;
int c;//Convertire les textBox en int int.TryParse(TxtQteCmd.Text.Trim(), out a); int.TryParse(TxtQteStock.Text.Trim(), out b); int.TryParse(TxtPrixUnitaire.Text.Trim(), out c); if (a <= b) { total = a \* c; total\_achat = 0; try { setConnection(); sql\_con.Open(); using (OleDbCommand cmd = sql\_con.CreateCommand()) { cmd.CommandText = "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)"; cmd.Parameters.AddWithValue("@ref\_det", TxtRefProduit.Text); cmd.Parameters.AddWithValue("@qute\_det", TxtQteCmd.Text); cmd.Parameters.AddWithValue("@Designation", TxtDesignation.Text); cmd.Parameters.AddWithValue("@Prix\_unitaire\_HT", TxtPrixUnitaire.Text); cmd.Parameters.AddWithValue("@Prix\_total\_HT", total);
-
the goal is to add and save later I can do it once when I want to do it for a second time I have an error: unable to find table 0, I must close the form and open it again so that I can do another one ... how to solve this problem without closing my form before?
private void BtnAjouter_Click(object sender, EventArgs e)
{
int total;
decimal total_achat;
//si les champs sont vides
if (TxtDesignation.Text == "" || TxtPrixUnitaire.Text == "" || TxtQteCmd.Text == "" || TxtQteStock.Text == "" || TxtRefProduit.Text == "")
{
MessageBox.Show("Rassurez vous que tous les champs ont bien été rempli.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
//Vérifier si la valeur saisie est numeric
if (Int32.TryParse(TxtQteCmd.Text, out int value) && TxtRefProduit.Text != "")
{
//Vérifier si la commande est inferieur ou egale au stock
int a = 0;
int b = 0;
int c;//Convertire les textBox en int int.TryParse(TxtQteCmd.Text.Trim(), out a); int.TryParse(TxtQteStock.Text.Trim(), out b); int.TryParse(TxtPrixUnitaire.Text.Trim(), out c); if (a <= b) { total = a \* c; total\_achat = 0; try { setConnection(); sql\_con.Open(); using (OleDbCommand cmd = sql\_con.CreateCommand()) { cmd.CommandText = "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)"; cmd.Parameters.AddWithValue("@ref\_det", TxtRefProduit.Text); cmd.Parameters.AddWithValue("@qute\_det", TxtQteCmd.Text); cmd.Parameters.AddWithValue("@Designation", TxtDesignation.Text); cmd.Parameters.AddWithValue("@Prix\_unitaire\_HT", TxtPrixUnitaire.Text); cmd.Parameters.AddWithValue("@Prix\_total\_HT", total);
Just what does
DB
have to do with anything?DB.Fill(DS);
It doesn't have any obvious relation to the Connection object, or to the Command - so why would you expect it to do anything useful? Come on man, you need to start thinking here - instead of just copy'n'paste code from somewhere else and hoping it works!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
Just what does
DB
have to do with anything?DB.Fill(DS);
It doesn't have any obvious relation to the Connection object, or to the Command - so why would you expect it to do anything useful? Come on man, you need to start thinking here - instead of just copy'n'paste code from somewhere else and hoping it works!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
you may be right but i have declared its objects to display the info in the datagridview
private OleDbDataAdapter DB;
private DataSet DS = new DataSet ();
private DataTable DT = new DataTable ();
thanks for guiding meOh gawd, I only stopped banging my head on the desk yesterday ... Stop and think. Where are you getting the data from? How does the data source connect to the DataSet? How does the DataSet connect to the DataTable? How does the DataTable connect to the DataGridView? Any one of those links is wrong ... and you don't get data ... Seriously man - get a book and start reading. You aren't helping yourself by trying and hoping - all you do is make yourself look ... umm ... pretty silly, he said as politely as he could manage. :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
Oh gawd, I only stopped banging my head on the desk yesterday ... Stop and think. Where are you getting the data from? How does the data source connect to the DataSet? How does the DataSet connect to the DataTable? How does the DataTable connect to the DataGridView? Any one of those links is wrong ... and you don't get data ... Seriously man - get a book and start reading. You aren't helping yourself by trying and hoping - all you do is make yourself look ... umm ... pretty silly, he said as politely as he could manage. :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
thank you sir i will read and get back to you because i feel like an idiot. I will review her and let you know.
Don't feel like an idiot, just learn the basics - because until you understand what you are doing, you are just whistling in the dark and hoping the noise attracts solutions rather than monsters ... :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
Don't feel like an idiot, just learn the basics - because until you understand what you are doing, you are just whistling in the dark and hoping the noise attracts solutions rather than monsters ... :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
Don't feel like an idiot, just learn the basics - because until you understand what you are doing, you are just whistling in the dark and hoping the noise attracts solutions rather than monsters ... :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
sir you are right these lines were useless, they were useless ...
I just saw its The DataAdapter object serves as a link between a DataSet object and a data source.
A .NET data provider will use a DataAdapter object to fill data with a DataSet and then pass on the changes made to a data source. -
sir you are right these lines were useless, they were useless ...
I just saw its The DataAdapter object serves as a link between a DataSet object and a data source.
A .NET data provider will use a DataAdapter object to fill data with a DataSet and then pass on the changes made to a data source.Yes it does - but that doesn't mean that you create an instance and "magic happens" :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
Yes it does - but that doesn't mean that you create an instance and "magic happens" :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
yes sir i already did to change the datagridview
private void LoadDB()
{
setConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string CommandText = "SELECT * FROM Detail_temp";
DB = new OleDbDataAdapter(CommandText, sql_con);
DS.Reset();
DB.Fill(DS);
DT = DS.Tables[0];
dataGridView1.DataSource = DT;
sql_con.Close();
}maybe I'm wrong? but I did it to see my recordings in the datagridview
-
yes sir i already did to change the datagridview
private void LoadDB()
{
setConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string CommandText = "SELECT * FROM Detail_temp";
DB = new OleDbDataAdapter(CommandText, sql_con);
DS.Reset();
DB.Fill(DS);
DT = DS.Tables[0];
dataGridView1.DataSource = DT;
sql_con.Close();
}maybe I'm wrong? but I did it to see my recordings in the datagridview
That's better - but in the code you showed to start with, you didn't do that, did you?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
That's better - but in the code you showed to start with, you didn't do that, did you?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
Off topic, but why do you keep putting your messages in text tags?
Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.