473,473 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem OledbDataAdapter

I made a oledbdataadapter with this code

Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
Dim veza As OleDb.OleDbConnection = New
OleDb.OleDbConnection(Global.Diplomski1.My.MySetti ngs.Default.Studenti1Connection)
Dim tableMapping As System.Data.Common.DataTableMapping = New
System.Data.Common.DataTableMapping("Marko", "Table1")
For i = 0 To Form2.Studenti1Data.Tables.Item(0).Columns.Count - 1
tableMapping.ColumnMappings.Add(Form2.Studenti1Dat a.Tables.Item(0).Columns.Item(i).ColumnName,
Form2.Studenti1Data.Tables.Item(0).Columns.Item(i) .ColumnName)
Next i

nova.TableMappings.Add(tableMapping)

nova.MissingMappingAction = MissingMappingAction.Passthrough
nova.MissingSchemaAction = MissingSchemaAction.AddWithKey
nova.AcceptChangesDuringUpdate = True

nova.SelectCommand.Connection = veza
nova.SelectCommand.CommandType = CommandType.Text
nova.SelectCommand.CommandText = "SELECT * FROM " & nova1
nova.SelectCommand.Parameters.Add("Broj iksice",
OleDb.OleDbType.Double, 0, "Broj iksice")
nova.SelectCommand.Parameters.Add("Prezime", OleDb.OleDbType.WChar,
0, "Prezime")
nova.SelectCommand.Parameters.Add("Ime", OleDb.OleDbType.WChar, 0,
"Ime")
nova.SelectCommand.Parameters.Add("Broj indeksa",
OleDb.OleDbType.WChar, 0, "Broj indeksa")
nova.SelectCommand.Parameters.Add("Broj pohadjanja",
OleDb.OleDbType.WChar, 0, "Broj pohadjanja")
nova.UpdateCommand.Connection = veza
nova.UpdateCommand.CommandType = CommandType.Text
nova.UpdateCommand.CommandText = "UPDATE " & nova1 & " SET Broj
iksice=?, Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"
nova.InsertCommand.Connection = veza
nova.InsertCommand.CommandType = CommandType.Text
nova.InsertCommand.CommandText = "INSERT INTO " & nova1 & " (Broj
iksice, Prezime, Ime, Broj indeksa, Broj pohadjanja) VALUES (?,?,?,?,?)"

nova.DeleteCommand.Connection = veza
nova.DeleteCommand.CommandType = CommandType.Text
nova.DeleteCommand.CommandText = "UPDATE " & nova1 & " SET Broj
iksice=?, Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"

If nova2 = "Fill" Then

nova.Fill(Form2.Studenti1Data.Tables.Item(Index(Co mboBox1.Text)))

End If
End Sub

I have an access database and connected it to my project, but when I execute
it and call this procedure program stops at nova.SelectCommand.Connection =
veza
with this exception

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Diplomski1"
StackTrace:
at Diplomski1.Form1.Novo(String nova1, String nova2) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form1.v b:line 201
at Diplomski1.Form2.Form2_Load(Object sender, EventArgs e) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form2.v b:line 12
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow( HandleRef hWnd,
Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolea n value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at Diplomski1.Form1.Button1_Click(Object sender, EventArgs e) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form1.v b:line 8
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at Diplomski1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
--------------------------------------------------------------------------------
Can anybody help me?
Jan 19 '07 #1
1 1577
Where are you opening the connection? Try adding this:

veza.Open()

And at the end, be sure to close it again. Or wrap the whole
thing in a Using statement.

Robin S.
---------------------------
"explode" <ur**@mzos.hrwrote in message
news:eo**********@news1.carnet.hr...
I made a oledbdataadapter with this code

Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
Dim veza As OleDb.OleDbConnection = New
OleDb.OleDbConnection(Global.Diplomski1.My.MySetti ngs.Default.Studenti1Connection)
Dim tableMapping As System.Data.Common.DataTableMapping = New
System.Data.Common.DataTableMapping("Marko", "Table1")
For i = 0 To Form2.Studenti1Data.Tables.Item(0).Columns.Count -
1

tableMapping.ColumnMappings.Add(Form2.Studenti1Dat a.Tables.Item(0).Columns.Item(i).ColumnName,
Form2.Studenti1Data.Tables.Item(0).Columns.Item(i) .ColumnName)
Next i

nova.TableMappings.Add(tableMapping)

nova.MissingMappingAction = MissingMappingAction.Passthrough
nova.MissingSchemaAction = MissingSchemaAction.AddWithKey
nova.AcceptChangesDuringUpdate = True

nova.SelectCommand.Connection = veza
nova.SelectCommand.CommandType = CommandType.Text
nova.SelectCommand.CommandText = "SELECT * FROM " & nova1
nova.SelectCommand.Parameters.Add("Broj iksice",
OleDb.OleDbType.Double, 0, "Broj iksice")
nova.SelectCommand.Parameters.Add("Prezime",
OleDb.OleDbType.WChar, 0, "Prezime")
nova.SelectCommand.Parameters.Add("Ime", OleDb.OleDbType.WChar,
0, "Ime")
nova.SelectCommand.Parameters.Add("Broj indeksa",
OleDb.OleDbType.WChar, 0, "Broj indeksa")
nova.SelectCommand.Parameters.Add("Broj pohadjanja",
OleDb.OleDbType.WChar, 0, "Broj pohadjanja")
nova.UpdateCommand.Connection = veza
nova.UpdateCommand.CommandType = CommandType.Text
nova.UpdateCommand.CommandText = "UPDATE " & nova1 & " SET Broj
iksice=?, Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"
nova.InsertCommand.Connection = veza
nova.InsertCommand.CommandType = CommandType.Text
nova.InsertCommand.CommandText = "INSERT INTO " & nova1 & "
(Broj iksice, Prezime, Ime, Broj indeksa, Broj pohadjanja) VALUES
(?,?,?,?,?)"

nova.DeleteCommand.Connection = veza
nova.DeleteCommand.CommandType = CommandType.Text
nova.DeleteCommand.CommandText = "UPDATE " & nova1 & " SET Broj
iksice=?, Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"

If nova2 = "Fill" Then
nova.Fill(Form2.Studenti1Data.Tables.Item(Index(Co mboBox1.Text)))

End If
End Sub

I have an access database and connected it to my project, but when I
execute it and call this procedure program stops at
nova.SelectCommand.Connection = veza
with this exception

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Diplomski1"
StackTrace:
at Diplomski1.Form1.Novo(String nova1, String nova2) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form1.v b:line 201
at Diplomski1.Form2.Form2_Load(Object sender, EventArgs e) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form2.v b:line 12
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow( HandleRef
hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolea n value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at Diplomski1.Form1.Button1_Click(Object sender, EventArgs e) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form1.v b:line 8
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at Diplomski1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean
checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
--------------------------------------------------------------------------------
Can anybody help me?

Jan 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Aaron Smith | last post by:
I can't seem to get my table styles to apply to my DataGrid. In order for them to apply correctly, what exactly has to be set in the DataSource and DataMember, and then the DataMapping properties?...
2
by: Mika M | last post by:
My contact has really old Access 2.0 database still in their production use, and application which uses that is propably made by VB5 or VB6. Now I should to do few SQL-queries and make charts...
0
by: A.J | last post by:
There is a : 1.DataGrid: Columns-->firstName,LastName,EMail,PhoneNumber 2.GroupBox: controls-->4 TextBoxes(firstName,LastName,EMail,PhoneNumber) 3.Both DataGrid and GroupBox are binded to the...
1
by: gkellymail | last post by:
I currently have a class with 29 data adapters and I will probably add a few more as time goes on. When I was testing earlier, i had 28 of them pointing to one connection and 1 pointing to a...
2
by: Scotty | last post by:
I get stuck to write an update, insert and delete command, i am looking for some help to start Whats the best way to update 2 tables toe the database (Access) below my code used to load my...
3
by: Mitch W | last post by:
Consider the following: I have two Access tables: TableA & TableB TableA is a list of Names with a ZipID TableB is a list of City, States, and Zips with a ZipID as a primary key...
1
by: dhyder | last post by:
OK, like the title says my error is Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. I have looked into this a lot, but have not...
13
by: slinky | last post by:
I'm working on a problem with a form with 6 textboxes and a submit button for adding data to an Access database.I changed a few things and got it down to 1 error!. I have a Sub Page_Load and a Sub...
0
by: Syoam4ka | last post by:
My project is about jewellery. I have devided my jewelery into main types, which each one of them has sub types, and each one those sub types has the jewellery. I have a tabcontainer. It includes...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.