Hey everyone.
Freshly out of college from a programming course. To be honest, I was not able to learn everything as much as others, I learn much better by experimenting and such, and I find that I am getting good in VB right now. I am using VS 2008, with MySQL connector and WAMP as a means of going into my database. After writing my entire code, I keep getting errors on Inserting data from an unbound datagridview from my form onto my tableadapter and into the database itself. Below is the code, I would highly appreciate the assistance, as I am doing this side job at work to try to impress the boss
thanks a bunch guys! I willd o my best to help others as well.
Freshly out of college from a programming course. To be honest, I was not able to learn everything as much as others, I learn much better by experimenting and such, and I find that I am getting good in VB right now. I am using VS 2008, with MySQL connector and WAMP as a means of going into my database. After writing my entire code, I keep getting errors on Inserting data from an unbound datagridview from my form onto my tableadapter and into the database itself. Below is the code, I would highly appreciate the assistance, as I am doing this side job at work to try to impress the boss
Dim MySQLConnection As New MySqlConnection("server=localhost;User Id=webuser;Persist Security Info=True;database=time manager;password=webuser") 'Create Command object Dim NonQueryCommand As MySqlCommand = MySQLConnection.CreateCommand() Try MySQLConnection.Open() NonQueryCommand.CommandText = _ "INSERT INTO info(Date, StartTime, EndTime, TimeTaken, CompanyName, ContactName, Description, Chargeable, Rate, TotalCharges)" + _ "VALUES(@Date, @StartTime, @EndTime, @TimeTaken, @Companyname, @ContactName, @Description, @Chargeable, @Rate, @TotalCharges)" NonQueryCommand.Parameters.AddWithValue("@Date", MySqlDbType.VarChar) NonQueryCommand.Parameters.AddWithValue("@StartTime", MySqlDbType.VarChar) NonQueryCommand.Parameters.AddWithValue("@EndTime", MySqlDbType.VarChar) NonQueryCommand.Parameters.AddWithValue("@TimeTaken", MySqlDbType.VarChar) NonQueryCommand.Parameters.AddWithValue("@CompanyName", MySqlDbType.VarChar) NonQueryCommand.Parameters.AddWithValue("@ContactName", MySqlDbType.VarChar) NonQueryCommand.Parameters.AddWithValue("@Description", MySqlDbType.Text) NonQueryCommand.Parameters.AddWithValue("@Chargeable", MySqlDbType.VarChar) NonQueryCommand.Parameters.AddWithValue("@Rate", MySqlDbType.VarChar) NonQueryCommand.Parameters.AddWithValue("@TotalCharges", MySqlDbType.VarChar) NonQueryCommand.Prepare() For Each row As DataGridViewRow In DailyReportGrid.Rows NonQueryCommand.Parameters("@Date").Value = row.Cells("DateColumn").Value NonQueryCommand.Parameters("@StartTime").Value = row.Cells("StartTimeColumn").Value NonQueryCommand.Parameters("@EndTime").Value = row.Cells("EndTimeColumn").Value NonQueryCommand.Parameters("@TimeTaken").Value = row.Cells("TimeTakenColumn").Value NonQueryCommand.Parameters("@CompanyName").Value = row.Cells("CompanyNameColumn").Value NonQueryCommand.Parameters("@ContactName").Value = row.Cells("ContactNameColumn").Value NonQueryCommand.Parameters("@Description").Value = row.Cells("DescriptionColumn").Value NonQueryCommand.Parameters("@Chargeable").Value = row.Cells("ChargeableColumn").Value NonQueryCommand.Parameters("@Rate").Value = row.Cells("RateColumn").Value NonQueryCommand.Parameters("@TotalCharges").Value = row.Cells("TotalChargesColumn").Value Next NonQueryCommand.ExecuteNonQuery() Catch ex As MySqlException MessageBox.Show(ex.ToString) Finally MySQLConnection.Close() End Try
Last edited by a moderator: