473,657 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem OledbDataAdapte r

I made a oledbdataadapte r with this code

Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter
Dim veza As OleDb.OleDbConn ection = New
OleDb.OleDbConn ection(Global.D iplomski1.My.My Settings.Defaul t.Studenti1Conn ection)
Dim tableMapping As System.Data.Com mon.DataTableMa pping = New
System.Data.Com mon.DataTableMa pping("Marko", "Table1")
For i = 0 To Form2.Studenti1 Data.Tables.Ite m(0).Columns.Co unt - 1
tableMapping.Co lumnMappings.Ad d(Form2.Student i1Data.Tables.I tem(0).Columns. Item(i).ColumnN ame,
Form2.Studenti1 Data.Tables.Ite m(0).Columns.It em(i).ColumnNam e)
Next i

nova.TableMappi ngs.Add(tableMa pping)

nova.MissingMap pingAction = MissingMappingA ction.Passthrou gh
nova.MissingSch emaAction = MissingSchemaAc tion.AddWithKey
nova.AcceptChan gesDuringUpdate = True

nova.SelectComm and.Connection = veza
nova.SelectComm and.CommandType = CommandType.Tex t
nova.SelectComm and.CommandText = "SELECT * FROM " & nova1
nova.SelectComm and.Parameters. Add("Broj iksice",
OleDb.OleDbType .Double, 0, "Broj iksice")
nova.SelectComm and.Parameters. Add("Prezime", OleDb.OleDbType .WChar,
0, "Prezime")
nova.SelectComm and.Parameters. Add("Ime", OleDb.OleDbType .WChar, 0,
"Ime")
nova.SelectComm and.Parameters. Add("Broj indeksa",
OleDb.OleDbType .WChar, 0, "Broj indeksa")
nova.SelectComm and.Parameters. Add("Broj pohadjanja",
OleDb.OleDbType .WChar, 0, "Broj pohadjanja")
nova.UpdateComm and.Connection = veza
nova.UpdateComm and.CommandType = CommandType.Tex t
nova.UpdateComm and.CommandText = "UPDATE " & nova1 & " SET Broj
iksice=?, Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"
nova.InsertComm and.Connection = veza
nova.InsertComm and.CommandType = CommandType.Tex t
nova.InsertComm and.CommandText = "INSERT INTO " & nova1 & " (Broj
iksice, Prezime, Ime, Broj indeksa, Broj pohadjanja) VALUES (?,?,?,?,?)"

nova.DeleteComm and.Connection = veza
nova.DeleteComm and.CommandType = CommandType.Tex t
nova.DeleteComm and.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(Ind ex(ComboBox1.Te xt)))

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.SelectComm and.Connection =
veza
with this exception

System.NullRefe renceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Diploms ki1"
StackTrace:
at Diplomski1.Form 1.Novo(String nova1, String nova2) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm1.vb:line 201
at Diplomski1.Form 2.Form2_Load(Ob ject sender, EventArgs e) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm2.vb:line 12
at System.Windows. Forms.Form.OnLo ad(EventArgs e)
at System.Windows. Forms.Form.OnCr eateControl()
at System.Windows. Forms.Control.C reateControl(Bo olean fIgnoreVisible)
at System.Windows. Forms.Control.C reateControl()
at System.Windows. Forms.Control.W mShowWindow(Mes sage& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.Form.WmSh owWindow(Messag e& m)
at System.Windows. Forms.Form.WndP roc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&
m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.SafeNativ eMethods.ShowWi ndow(HandleRef hWnd,
Int32 nCmdShow)
at System.Windows. Forms.Control.S etVisibleCore(B oolean value)
at System.Windows. Forms.Form.SetV isibleCore(Bool ean value)
at System.Windows. Forms.Control.S how()
at Diplomski1.Form 1.Button1_Click (Object sender, EventArgs e) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm1.vb:line 8
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&
m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
commandLine)
at Diplomski1.My.M yApplication.Ma in(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean checkAptModel)
at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt, String[] activationCusto mData)
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
--------------------------------------------------------------------------------
Can anybody help me?
Jan 19 '07 #1
1 1591
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.hrwr ote in message
news:eo******** **@news1.carnet .hr...
I made a oledbdataadapte r with this code

Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter
Dim veza As OleDb.OleDbConn ection = New
OleDb.OleDbConn ection(Global.D iplomski1.My.My Settings.Defaul t.Studenti1Conn ection)
Dim tableMapping As System.Data.Com mon.DataTableMa pping = New
System.Data.Com mon.DataTableMa pping("Marko", "Table1")
For i = 0 To Form2.Studenti1 Data.Tables.Ite m(0).Columns.Co unt -
1

tableMapping.Co lumnMappings.Ad d(Form2.Student i1Data.Tables.I tem(0).Columns. Item(i).ColumnN ame,
Form2.Studenti1 Data.Tables.Ite m(0).Columns.It em(i).ColumnNam e)
Next i

nova.TableMappi ngs.Add(tableMa pping)

nova.MissingMap pingAction = MissingMappingA ction.Passthrou gh
nova.MissingSch emaAction = MissingSchemaAc tion.AddWithKey
nova.AcceptChan gesDuringUpdate = True

nova.SelectComm and.Connection = veza
nova.SelectComm and.CommandType = CommandType.Tex t
nova.SelectComm and.CommandText = "SELECT * FROM " & nova1
nova.SelectComm and.Parameters. Add("Broj iksice",
OleDb.OleDbType .Double, 0, "Broj iksice")
nova.SelectComm and.Parameters. Add("Prezime",
OleDb.OleDbType .WChar, 0, "Prezime")
nova.SelectComm and.Parameters. Add("Ime", OleDb.OleDbType .WChar,
0, "Ime")
nova.SelectComm and.Parameters. Add("Broj indeksa",
OleDb.OleDbType .WChar, 0, "Broj indeksa")
nova.SelectComm and.Parameters. Add("Broj pohadjanja",
OleDb.OleDbType .WChar, 0, "Broj pohadjanja")
nova.UpdateComm and.Connection = veza
nova.UpdateComm and.CommandType = CommandType.Tex t
nova.UpdateComm and.CommandText = "UPDATE " & nova1 & " SET Broj
iksice=?, Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"
nova.InsertComm and.Connection = veza
nova.InsertComm and.CommandType = CommandType.Tex t
nova.InsertComm and.CommandText = "INSERT INTO " & nova1 & "
(Broj iksice, Prezime, Ime, Broj indeksa, Broj pohadjanja) VALUES
(?,?,?,?,?)"

nova.DeleteComm and.Connection = veza
nova.DeleteComm and.CommandType = CommandType.Tex t
nova.DeleteComm and.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(Ind ex(ComboBox1.Te xt)))

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.SelectComm and.Connection = veza
with this exception

System.NullRefe renceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Diploms ki1"
StackTrace:
at Diplomski1.Form 1.Novo(String nova1, String nova2) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm1.vb:line 201
at Diplomski1.Form 2.Form2_Load(Ob ject sender, EventArgs e) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm2.vb:line 12
at System.Windows. Forms.Form.OnLo ad(EventArgs e)
at System.Windows. Forms.Form.OnCr eateControl()
at System.Windows. Forms.Control.C reateControl(Bo olean
fIgnoreVisible)
at System.Windows. Forms.Control.C reateControl()
at System.Windows. Forms.Control.W mShowWindow(Mes sage& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.Form.WmSh owWindow(Messag e& m)
at System.Windows. Forms.Form.WndP roc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.SafeNativ eMethods.ShowWi ndow(HandleRef
hWnd, Int32 nCmdShow)
at System.Windows. Forms.Control.S etVisibleCore(B oolean value)
at System.Windows. Forms.Form.SetV isibleCore(Bool ean value)
at System.Windows. Forms.Control.S how()
at Diplomski1.Form 1.Button1_Click (Object sender, EventArgs e) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm1.vb:line 8
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext
context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
commandLine)
at Diplomski1.My.M yApplication.Ma in(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean
checkAptModel)
at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt, String[] activationCusto mData)
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.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
1061
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? I keep trying all different combinations of DataSets, tables, and even DataViews, but it just isn't working... I have a DataSet that has the following: Table1 |_ Table 2
2
998
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 according those queries of this Access database with VB.NET. I tried to do it like this way... Dim strConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\servername\thepath...\database.mdb;User Id=admin;Password=;"
0
1098
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 same datasource(Dataset) and Share the same BINDINGCONTEXT ie on clicking a record in the grid;we can see the same record in the groupbox. $$$$$$$$$$$$$$$$$$$$$$Edited $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
1
1669
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 different one by mistake. This really caused some confusion for a while. What I would like to do is use reflection to have the object scan itself and pick out all of the data adapters and then for each set the connection for all of the various...
2
2322
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 data.(2 tables) Do someone has a good sample code to help me? Many thanks in advance, Marc.
3
3151
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 autonumbered On a Windows Form I have two text boxes, Name (from TableA) and City (from
1
3058
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 been able to find a solution to it. <%@ Page Language="c#" runat="server" debug="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <script runat="server"> OleDbConnection conn = new...
13
1621
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 btnAdd: (It still doesn't like the 'SourceVersion' in the Sub Page_Load). Also I viewed the .aspx in the browser and got an error which I posted complete at the bottom of this post). Thanks for any clues... I'm almost there!!
0
1370
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 tabpanels such as:Catalog,Terms,SiteMap.ViewCart ,etc. All the jewellery Intro is in the Catalog panel. when I first click the Catalog panel it Introduces me all the main types of the jewellery(It's all done dynamically from the cs file).The...
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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 we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.