[RESOLVED] What i 'am i doing qrong
it will not add to the database just add to the datagridview. it will open and show the Db but will not add
Best Regards
Code:
Imports System.Windows.Forms
Imports System
Imports System.Data.OleDb
Imports System.Collections
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Threading
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Public Class Vaction
Dim cmddlt As OleDbDataAdapter
Dim cndlt As OleDbConnection
Dim dsdlt As New DataSet
Dim dsdlt1 As DataRow
Dim cmddlt2 As System.Data.OleDb.OleDbDataAdapter
Dim cndlt2 As System.Data.OleDb.OleDbConnection
Dim dsdlt3 As New System.Data.DataSet()
Dim dsdlt2 As DataRow
Dim intCurrentIndex As Integer = 0
Private Sub Vaction_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'Arbeite.Show()
End Sub
Private Sub Vaction_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.dtpDateTimePicker1.Format = DateTimePickerFormat.Custom
' Display the date as "Mon 26 Feb 2001".
Me.dtpDateTimePicker1.CustomFormat = "dd / MM / yyyy"
Me.txtStart.Text = Me.dtpDateTimePicker1.Text
cndlt = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Arbeite.accdb;Persist Security Info=False;")
cmddlt = New OleDbDataAdapter("select * from Vaction", cndlt)
cmddlt = New OleDbDataAdapter("select * from Vaction Where ID1 = ID1", cndlt)
cmddlt.InsertCommand = New OleDbCommand("INSERT INTO Vaction (Start_Date,End_Date,Begain_Bal,Used,End_Bal) VALUES (Start_Date,End_Date,Begain_Bal,Used,End_Bal)")
cmddlt.InsertCommand.Connection = cndlt
cmddlt.InsertCommand.Parameters.Add("Start_Date", OleDbType.VarChar, 40, "Start_Date")
cmddlt.InsertCommand.Parameters.Add("End_Date", OleDbType.VarChar, 40, "End_Date")
cmddlt.InsertCommand.Parameters.Add("Begain_Bal", OleDbType.VarChar, 40, "Begain_Bal")
cmddlt.InsertCommand.Parameters.Add("Used", OleDbType.VarChar, 40, "Used")
cmddlt.InsertCommand.Parameters.Add("End_Bal", OleDbType.VarChar, 110, "End_Bal")
cmddlt.UpdateCommand = New OleDbCommand("UPDATE Vaction SET Start_Date = @Start_Date,End_Date = @End_Date,Begain_Bal = @Begain_Bal,Used = @Used,End_Bal = @End_Bal WHERE ID1 = @ID1")
cmddlt.UpdateCommand.Connection = cndlt
cmddlt.UpdateCommand.Parameters.Add("@Start_Date", OleDbType.VarChar, 40, "Start_Date")
cmddlt.UpdateCommand.Parameters.Add("@End_Date", OleDbType.VarChar, 40, "End_Date")
cmddlt.UpdateCommand.Parameters.Add("@Begain_Bal", OleDbType.VarChar, 40, "Begain_Bal")
cmddlt.UpdateCommand.Parameters.Add("@Used", OleDbType.VarChar, 40, "Used")
cmddlt.UpdateCommand.Parameters.Add("@End_Bal", OleDbType.VarChar, 40, "End_Bal")
cmddlt.UpdateCommand.Parameters.Add("@Start_Date", OleDbType.Integer, 5, "Start_Date").SourceVersion = DataRowVersion.Original
cmddlt.DeleteCommand = New OleDbCommand("DELETE FROM Vaction WHERE ID1 = @ID1")
cmddlt.DeleteCommand.Connection = cndlt
cmddlt.DeleteCommand.Parameters.Add("@ID1", OleDbType.Integer, 5, "ID1").SourceVersion = DataRowVersion.Original
Dim db_name As String = Application.StartupPath
db_name = db_name.Substring(0, db_name.LastIndexOf("\"))
db_name &= "\Arbeite.accdb"
'Try
cndlt.Open()
'cn2.Open()
cmddlt.Fill(dsdlt, "Start_Date")
DataGridView10.DataSource = dsdlt.Tables("Start_Date")
'Dim dry As DataRow
'Gets a reference to a new row.
'dsAdd.Tables(0).Rows.Add(drAdd)
cmddlt.Update(dsdlt, "Start_Date")
dsdlt.AcceptChanges()
cndlt.Close()
Re: What i 'am i doing qrong
Check my sig... there's a link "I swear I saved my data, where'd it run off to?" ... read, see if it's something that applies in this case. If not, let us know.
-tg
Re: What i 'am i doing qrong
OH... I should have taken a closer look there... for starters... your insert query is incorrect...
All of your query commands aren't right as far as I can tell...
INSERT INTO Vaction (Start_Date,End_Date,Begain_Bal,Used,End_Bal) VALUES (Start_Date,End_Date,Begain_Bal,Used,End_Bal)
should be
INSERT INTO Vaction (Start_Date,End_Date,Begain_Bal,Used,End_Bal) VALUES (?,?,?,?,?)
Access doesn't use named parameters... so you have to mark your parameters with a place holder - the "?" ... and then add your parameters IN ORDER, LEFT TO RIGHT. When you add them, you can give them a name for readability, but since it's going to use positional parameters, you can basically name them anything you want.
Also, there's no point of calling the Update or AcceptChanges since you've only just filled the datatable, there are no changes to update or accept.
-tg
Re: What i 'am i doing qrong
thank you for the help its working