I am trying to update a record using one of samples provided and I always have the following error:
"Reference to a non-shared member requires an object reference"
The code I use is as follows:
Dim
totalsRow As mdstats1DataSet.TotalsRowtotalsRow = mdstats1DataSet.Totals.FindByRecordID(1)
totalsRow.smtpin = smtpin
totalsRow.smtpout = smtpout
The error is on the "mdstats1DataSet.Totals"
Can anyone help me
BTW, I am using VB Express and SQL Express

updating records
David Leibowitz
Blaine,
I think that you probably still do not have an instance of the mdstatsDataSet. Why don't you post the code for the whole form ... it might be easier for us to help you that way.
squeakstar
Cornishboy
Well, I am a complete beginner to this so a could be missing something critcal. All I have been doing is using the MSDN help files that came with VB Express.
Here is an explanation of what I am trying to do;
I have a database in SQL express with a table called "totals", it has only one row of data and will only have one row of data, all I want to do write the new valuses to that table.
The example from the help files says this;
Dim customerRow() As Data.DataRow
customerRow = DataSet1.Tables("Customers").Select("CustomerID = 'ALFKI'") customerRow(0)("CompanyName") = "Updated Company Name"
customerRow(0)("City") = "Seattle"
I have modified the the example to this:
Dim
totalsRow() As Data.DataRowtotalsRow = mdstatsDataSet.Tables("totals").Select("RecordID = 1")
totalsRow(0)("smtpin") = Ismtpin
totalsRow(0)("smtpout") = Ismtpout
however I get the following error on "mdstatsDataset.Tables":
Error 1 Reference to a non-shared member requires an object reference. F:\Documents\Visual Studio 2005\Projects\MD Stats counter\WindowsApplication3\Form1.vb 146 21 MD Stats counter
DerekM
The only thing I can get out of that error message is that you're trying to access a row in your DataTable when you have no rows.
You're gonna have to post some code ... including pointing out the line that caused the error. Doing a little debugging on your own might not be a bad idea either.
ChrisCC
RebEl
Michael Iacoviello
Private
Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim textline As String Dim count As String Dim field, l As String Dim stringlength, EqualSignPos, linecount As Single Me.Text = My.Application.Info.Titlelinecount = 0
FileOpen(1,
"C:\mdaemon\app\guicounts.dat", OpenMode.Input) While Not EOF(1)l = LineInput(1)
linecount = linecount + 1
End WhileFileClose(1)
ProgressBar1.Maximum = linecount
FileOpen(1,
"C:\mdaemon\app\guicounts.dat", OpenMode.Input)linecount = 0
While Not EOF(1)textline = LineInput(1)
linecount = linecount + 1
If textline <> "[GUI_Counts]" Thenstringlength = Len(textline)
EqualSignPos = InStr(1, textline,
"=")field = Microsoft.VisualBasic.Left(textline, EqualSignPos - 1)
count = Microsoft.VisualBasic.Right(textline, stringlength - EqualSignPos)
ProgressBar1.Value = linecount
Select Case field Case "Raw Today"TextBox4.Text = count
Case "SmtpIn Today"TextBox1.Text = count
Case "Spam Today"TextBox3.Text = count
Case "Virus Today"TextBox5.Text = count
Case "Pop Today"TextBox7.Text = count
Case "SmtpOut Today"TextBox2.Text = count
Case "MultiPop Today"TextBox8.Text = count
Case "SpamRefused Today"TextBox6.Text = count
Case "VirusRefused Today"TextBox37.Text = count
Case "Imap Today"TextBox9.Text = count
'Yesterday Case "SmtpIn Yesterday"TextBox18.Text = count
Case "Spam Yesterday"TextBox16.Text = count
Case "Virus Yesterday"TextBox14.Text = count
Case "Pop Yesterday"TextBox12.Text = count
Case "SmtpOut Yesterday"TextBox17.Text = count
Case "MultiPop Yesterday"TextBox11.Text = count
Case "SpamRefused Yesterday"TextBox13.Text = count
Case "VirusRefused Yesterday"TextBox38.Text = count
Case "Imap Yesterday"TextBox10.Text = count
Case "Raw Yesterday"TextBox15.Text = count
'2 days back Case "SmtpIn Back_2"TextBox27.Text = count
Case "Spam Back_2"TextBox25.Text = count
Case "Virus Back_2"TextBox23.Text = count
Case "Pop Back_2"TextBox21.Text = count
Case "SmtpOut Back_2"TextBox26.Text = count
Case "MultiPop Back_2"TextBox20.Text = count
Case "SpamRefused Back_2"TextBox22.Text = count
Case "VirusRefused Back_2"TextBox39.Text = count
Case "Imap Back_2"TextBox19.Text = count
Case "Raw Back_2"TextBox24.Text = count
'Totals Case "SmtpIn Total"TextBox36.Text = count
Case "Spam Total"TextBox34.Text = count
Case "Virus Total"TextBox32.Text = count
Case "Pop Total"TextBox30.Text = count
Case "SmtpOut Total"TextBox35.Text = count
Case "MultiPop Total"TextBox29.Text = count
Case "SpamRefused Total"TextBox31.Text = count
Case "VirusRefused Total"TextBox40.Text = count
Case "Imap Total"TextBox28.Text = count
Case "Raw Total"TextBox33.Text = count
End Select End If End WhileFileClose(1)
ProgressBar1.Visible =
False 'convert strings to integers Dim Ismtpin, Ismtpout, Ipop, Iraw, Iviruses, Ivirusesrefused, Ispam, Ispamrefused, Iimap, Imultipop As IntegerIsmtpin =
CInt(TextBox36.Text)Ismtpout =
CInt(TextBox35.Text)Ipop =
CInt(TextBox30.Text)Iraw =
CInt(TextBox33.Text)Iviruses =
CInt(TextBox32.Text)Ivirusesrefused =
CInt(TextBox40.Text)Ispam =
CInt(TextBox34.Text)Ispamrefused =
CInt(TextBox31.Text)Imultipop =
CInt(TextBox29.Text)Iimap =
CInt(TextBox28.Text)
Dim ds As mdstatsDataSet = New mdstatsDataSetds.totals(0).RecordID = 1
ds.totals(0).smtpin = Ismtpin
ds.totals(0).smtpout = Ismtpout
ds.totals(0).pop = Ipop
ds.totals(0).raw = Iraw
ds.totals(0).viruses = Iviruses
ds.totals(0).virusesrefused = Ivirusesrefused
ds.totals(0).spam = Ispam
ds.totals(0).spamrefused = Ispamrefused
ds.totals(0).imap = Iimap
ds.totals(0).multipop = Imultipop
rjhdakota
OK, so that kind of worked, now I am getting the following error when it executes
System.IndexOutOfRangeException was unhandled
Message="There is no row at position 0."
Source="System.Data"
StackTrace:
at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
at System.Data.DataRowCollection.get_Item(Int32 index)
at MDStats.mdstatsDataSet.totalsDataTable.get_Item(Int32 index) in F:\Documents\Visual Studio 2005\Projects\MD Stats counter\WindowsApplication3\mdstatsDataSet.Designer.vb:line 362
at MDStats.Form1.Form1_Load(Object sender, EventArgs e) in F:\Documents\Visual Studio 2005\Projects\MD Stats counter\WindowsApplication3\Form1.vb:line 151
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(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.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.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at MDStats.SplashScreen1.Timer1_Tick(Object sender, EventArgs e) in F:\Documents\Visual Studio 2005\Projects\MD Stats counter\WindowsApplication3\SplashScreen1.vb:line 51
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.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(Int32 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 MDStats.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.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Jeff Barton
This code will get a new row, set the values of that row, and then add the row to the DataSet. At that point, you can get a row by its record id:
forkart
Thats the funny part, there is a row of data in the table
difg
It's a lot of code, and I don't want to post that much. How do I look to see if I have an "instance" and how do I add one if I don't have it
Phattim
There is a Row of data in the database, All I want it to do is update the first row every time I run the program with the values.
TheCatty
David Wong Chien Shiung
This didn't work.
When the code executes I get this error
Object reference not set to an instance of an object.
on the line "totalsrow.smtpin = smtpin