Could I have some help with Sql statement.
-
This gives me an error and I've tried changing the values and formats within the brackets.
Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim Sql As String = "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')" Dim Sql2 As String = "Insert into tblTransaction values()" Dim conn As New OleDbConnection(strconn) Dim cmd As New OleDbCommand(Sql, conn) conn.Open() cmd.ExecuteNonQuery()
Is this pretty far off how you do an insert statement ? -
This gives me an error and I've tried changing the values and formats within the brackets.
Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim Sql As String = "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')" Dim Sql2 As String = "Insert into tblTransaction values()" Dim conn As New OleDbConnection(strconn) Dim cmd As New OleDbCommand(Sql, conn) conn.Open() cmd.ExecuteNonQuery()
Is this pretty far off how you do an insert statement ? -
have you tried inserting the fields? "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')7" "Insert into tblTransaction (field1,field2 ....) values(#12/05/06#,1,1,100,'this is it')7"
GUERVEN Truth or Consequence
-
This gives me an error and I've tried changing the values and formats within the brackets.
Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim Sql As String = "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')" Dim Sql2 As String = "Insert into tblTransaction values()" Dim conn As New OleDbConnection(strconn) Dim cmd As New OleDbCommand(Sql, conn) conn.Open() cmd.ExecuteNonQuery()
Is this pretty far off how you do an insert statement ?Also the newrow statement falls over with "null reference" when I code the dataadapter but not when I add in a dataadapter from the wizard. So what should the sql be here ? or the command so that I can creat a new row ?
Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim conn As New OleDbConnection(strConn) Dim Sql As String = "select * from tblTransaction" Dim adapter As OleDbDataAdapter adapter = New OleDbDataAdapter(Sql, conn) Dim ds As New DataSet Dim intc As Integer Dim str As String intc = adapter.Fill(ds) ' str = ds.Tables(0).Rows(0).Item(4) Me.Text = str Dim newrow As DataRow = ds.Tables("tblTransaction").NewRow
Please if you can help ? ml -- modified at 5:24 Thursday 27th July, 2006 -
-
Also the newrow statement falls over with "null reference" when I code the dataadapter but not when I add in a dataadapter from the wizard. So what should the sql be here ? or the command so that I can creat a new row ?
Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim conn As New OleDbConnection(strConn) Dim Sql As String = "select * from tblTransaction" Dim adapter As OleDbDataAdapter adapter = New OleDbDataAdapter(Sql, conn) Dim ds As New DataSet Dim intc As Integer Dim str As String intc = adapter.Fill(ds) ' str = ds.Tables(0).Rows(0).Item(4) Me.Text = str Dim newrow As DataRow = ds.Tables("tblTransaction").NewRow
Please if you can help ? ml -- modified at 5:24 Thursday 27th July, 2006You didn't tell the
DataSet
what the name of the tables are. Try:ds.Tables(0).NewRow
Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Also the newrow statement falls over with "null reference" when I code the dataadapter but not when I add in a dataadapter from the wizard. So what should the sql be here ? or the command so that I can creat a new row ?
Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim conn As New OleDbConnection(strConn) Dim Sql As String = "select * from tblTransaction" Dim adapter As OleDbDataAdapter adapter = New OleDbDataAdapter(Sql, conn) Dim ds As New DataSet Dim intc As Integer Dim str As String intc = adapter.Fill(ds) ' str = ds.Tables(0).Rows(0).Item(4) Me.Text = str Dim newrow As DataRow = ds.Tables("tblTransaction").NewRow
Please if you can help ? ml -- modified at 5:24 Thursday 27th July, 2006HI. from the flow of the code I assume you want to fill a datatable and then create a new row from it. you can directly fill a datatable without using a dataset. Here I replaced some of the code. With this method, you have a direct access to the dattable.
Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim conn As New OleDbConnection(strConn) Dim Sql As String = "select * from tblTransaction" Dim TblTrans as new datatable Dim adapter As OleDbDataAdapter adapter = New OleDbDataAdapter(Sql, conn) conn.open() intc = adapter.Fill(TBLtrans) Dim newrow As DataRow = TBLtrans.NewRow
furthermore, you can filter the datatable using its defaultview without using an extra dataview.TblTrans.DefaultView.RowStateFilter=DataViewRowState.Added Datagrid1.datasource = TBLtrans.defaultview
GUERVEN Truth or Consequence