Hi guys, First before start I'm new to c# , MySQL, visual studio.
I have a table 2 Tables
table #1 | shipment
| ShipmentID | VendorID |
table #2 | container
| ContainerID | ContainerStatus | ShipmentID | ShipDate | ShipBy |
| 1 | Closed | 1 | Current_TimeStamp | User |
1. I fill a combobox with data ( 1, 2, 3, 4, 5) as ContainerID run a insert in table 1 and after returns a shipmentid
2. then I add multiple values to a listbox: shiplist which I pass to a label "Shipping being made for" + (1,2,3,4,5) using String.Join(",", shiplist.values) to shipmadelist_lbl which pass in this format : (1,2,3,4,5)
3. I want to update each container in the listbox using :
UPDATE ewaste.container SET ContainerStatus='Shipped', ShipmentID='" + this.lastid_show_txt.Text + "', ShipDate=CURRENT_TIMESTAMP, ShippedBy='" + Properties.Settings.Default.LoggedUser + "' WHERE ContainerID IN '" + this.shipmadelist_lbl.Text + "'
but I receive a error I took a printscreen of the error with the form
I need more information I attached the shipment.cs (code only)
Ramesh MaruthiPosted Nov 3, 2014, 12:23 PM
Yw !! Good to know that ur problem solved :)
Good luck ...
Josue VegaPosted Nov 3, 2014, 8:41 AM
this is my code it will update each item in the listbox WHERE column='listbox.value" foreach
private void update_containers(object sender, EventArgs e)
{
foreach (var item in shiplist.Items)
{
string a =item.ToString();
string Query = "UPDATE ewaste.container SET ContainerStatus='Shipped', ShipmentID='" + this.lastid_show_txt.Text + "', ShipDate=CURRENT_TIMESTAMP, ShippedBy='" + Properties.Settings.Default.LoggedUser + "' WHERE ContainerID='" + a + "';";
MySqlConnection conDataBase = new MySqlConnection(Properties.Settings.Default.RPS);
MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
MySqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
while (myReader.Read())
{ }
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Ramesh MaruthiPosted Oct 31, 2014, 10:05 AM
Adding the items to list box :
http://www.dotnetperls.com/listbox
For Updating :
http://stackoverflow.com/questions/16652306/c-sharp-update-database-for-every-item-in-listbox
http://forums.asp.net/t/1446801.aspx?How+to+view+and+update+MS+SQL+table+using+ListBox+c+
Josue VegaPosted Oct 30, 2014, 7:54 PM
Sample:
So I want to add names to the listbox
Then run a UPDATE query for each of the otems in the listbox.
Ramesh MaruthiPosted Oct 30, 2014, 4:36 PM
SELECT * FROM employee_tbl
WHERE daily_typing_pages IN ( 250, 220, 170 );
IN after we should have the braces right ? I think that was the problem