By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

Problem OledbDataAdapter

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.