These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

need a littel help SQL vb.net

Author
shawn312
Cloaked Goof
Goonswarm Federation
#1 - 2013-01-01 08:29:40 UTC  |  Edited by: shawn312
1. I'm using visual studio 2010 ;

2.I am using a local SQL Compact 3.5 ".sdf" database attached to the project





Got it working but database is not up dating
NEW CODE

Quote:

Dim workrow As DataRow

Dim i As Integer

If Not Database1DataSet.Tables("items") Is Nothing Then
If Database1DataSet.Tables("items").Rows.Count > 0 Then

For i = 0 To DataGridView1.Rows.Count


workrow = Database1DataSet.Tables("items").NewRow()


workrow(1) = Val(DataGridView1.Rows(i).Cells(0).Value) 'if the table field is a number
workrow(2) = Val(DataGridView1.Rows(i).Cells(0).Value) 'if the table field is a number
workrow(3) = Val(DataGridView1.Rows(i).Cells(0).Value) 'if the table field is a number
workrow(4) = Val(DataGridView1.Rows(i).Cells(0).Value) 'if the table field is a number
workrow(5) = Val(DataGridView1.Rows(i).Cells(0).Value) 'if the table field is a number
workrow(6) = Val(DataGridView1.Rows(i).Cells(0).Value) 'if the table field is a number
workrow(7) = Val(DataGridView1.Rows(i).Cells(0).Value) 'if the table field is a number
workrow(8) = Val(DataGridView1.Rows(i).Cells(0).Value) 'if the table field is a number
Database1DataSet.Tables("items").Rows.Add(workrow)

Next
ItemsTableAdapter.Update(Database1DataSet)
End If
End If




anything past here is old
here is the code i am using

Quote:
Dim workrow As DataRow

Dim i As Integer

For i = 0 To DataGridView1.Rows.Count - 2

workrow = Database1DataSet.Tables("item").NewRow()


workrow(0) = Val(DataGridView1.Rows(i).Cells(0).Value)
workrow(1) = Val(DataGridView1.Rows(i).Cells(0).Value)
workrow(2) = Val(DataGridView1.Rows(i).Cells(0).Value)
workrow(3) = Val(DataGridView1.Rows(i).Cells(0).Value)
workrow(4) = Val(DataGridView1.Rows(i).Cells(0).Value)
workrow(5) = Val(DataGridView1.Rows(i).Cells(0).Value)
workrow(6) = Val(DataGridView1.Rows(i).Cells(0).Value)
workrow(7) = Val(DataGridView1.Rows(i).Cells(0).Value)
Database1DataSet.Tables("itam").Rows.Add(workrow)

Next

TableAdapterManager.UpdateAll(Database1DataSet)


and here is the exception
Quote:
System.NullReferenceException was unhandled

more info on the exception
Quote:
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Eve Online Lp
StackTrace:
at Eve_Online_Lp.Form1.Button2_Click(Object sender, EventArgs e) in c:\users\shawn\documents\visual studio 2010\Projects\Eve Online Lp\Eve Online Lp\Form1.vb:line 67
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs 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.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Eve_Online_Lp.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Desmont McCallock
#2 - 2013-01-01 08:32:53 UTC  |  Edited by: Desmont McCallock
What does 'Form1.vb:line 67' represent as code?

Is this line correct?
'Database1DataSet.Tables("itam").Rows.Add(workrow)'.
Shouldn't "itam" be 'item'?
shawn312
Cloaked Goof
Goonswarm Federation
#3 - 2013-01-01 08:39:46 UTC
Desmont McCallock wrote:
What does 'Form1.vb:line 67' represent as code?

Is this line correct?
'Database1DataSet.Tables("itam").Rows.Add(workrow)'.
Shouldn't "itam" be 'item'?




line 67 is
Quote:
workrow = Database1DataSet.Tables("item").NewRow()

and the code did not run all the way to the typo but its fixed now
Desmont McCallock
#4 - 2013-01-01 09:30:19 UTC  |  Edited by: Desmont McCallock
Ok. So either 'Database1DataSet' isn't initialized or 'Tables("item")' (which is more likely) is not returning an object. So if I where you I would check if calling 'Tables("item")' is correct.

Edit: Just saw your edit, so my guess was correct.

Edit 2: (Code suggestion, nothing to do (I think) with DB updating)
Change
If Not Database1DataSet.Tables("items") Is Nothing Then
If Database1DataSet.Tables("items").Rows.Count > 0 Then

To
If Not Database1DataSet.Tables("items") Is Nothing AndAlso Database1DataSet.Tables("items").Rows.Count > 0 Then

Edit 3:
DB not updating error (I suspect) is in 'Database1DataSet.Tables("items").Rows.Add(workrow)'