Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

DataGridView problem

[es] :: .NET :: DataGridView problem

[ Pregleda: 1864 | Odgovora: 6 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

brankec
Bosanski Brod

Član broj: 140157
Poruke: 161
*.teol.net.



Profil

icon DataGridView problem23.03.2010. u 11:52 - pre 170 meseci
Početnik sam u VB 2008. Imam sledeći problem:

Kad prvi put kliknem na PROVERA izvrši se SQL query i DataGrid bude popunjen i sve je uredu. Međutim kada ponovo kliknem isto dugme (bilo da sam promenio sifru ili ne) pojavljuje mi se sledeca greska:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Restoran rucak"
StackTrace:
at Restoran_rucak.Restoran.btnProvera_Click(Object sender, EventArgs e) in D:\Documents\Visual Studio 2008\Projects\Restoran rucak\Restoran.vb:line 17
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(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 Restoran_rucak.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly 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.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:


Neznam kako da ovo rešim.
Hvala na pomoći.

Prikačeni fajlovi
 
Odgovor na temu

malo_nj
novi sad

Član broj: 140825
Poruke: 104
213.196.121.*

Sajt: www.2advanced.com


Profil

icon Re: DataGridView problem23.03.2010. u 12:48 - pre 170 meseci
okaci code taj dio sto ti se desava kada kliknes na dugme.
 
Odgovor na temu

brankec
Bosanski Brod

Član broj: 140157
Poruke: 161
*.teol.net.



Profil

icon Re: DataGridView problem23.03.2010. u 13:00 - pre 170 meseci
Evo citavog koda:

Code:

'Import potrebnih Namespace-a
Imports System.Data.SqlClient
Imports System.Data

Public Class Restoran
    Dim objConnection As New SqlConnection("Server=; DataBase=; User=; Password=")
    Dim objDataAdapter As New SqlDataAdapter
    Dim objDataSet As New DataSet
    Dim objDataView As New DataView()

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnProvera_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProvera.Click

        'Ova IF naredba proverava da li je unešena šifra radnika
        If txtSifra.Text = "" Then
            MsgBox("Morate uneti sifru radnika:")
        Else
            objDataAdapter.SelectCommand = New SqlCommand
            objDataAdapter.SelectCommand.Connection = objConnection
            objDataAdapter.SelectCommand.CommandText = _
            "SELECT id, lastname, firstname, dt, long_name " & _
            "FROM users inner join events on users.no=events.userno inner join event_def on events.eventid=event_def.eventid " & _
            "WHERE dt BETWEEN @Vreme1 AND @Vreme2 AND id=@Sifra "
            objDataAdapter.SelectCommand.Parameters.AddWithValue("@Vreme1", dtpVreme.Value.Date)
            objDataAdapter.SelectCommand.Parameters.AddWithValue("@Vreme2", Now())
            objDataAdapter.SelectCommand.Parameters.AddWithValue("@Sifra", CType(txtSifra.Text, Integer))

            objConnection.Open()
            objDataAdapter.Fill(objDataSet, "Query")
            objConnection.Close()

            dgwQuery.AutoGenerateColumns = True
            dgwQuery.DataSource = objDataSet
            dgwQuery.DataMember = "Query"

            'Clean up
            objDataAdapter = Nothing
            objConnection = Nothing
            objDataView = Nothing
        End If
    End Sub
End Class
 
Odgovor na temu

malo_nj
novi sad

Član broj: 140825
Poruke: 104
213.196.121.*

Sajt: www.2advanced.com


Profil

icon Re: DataGridView problem23.03.2010. u 15:52 - pre 170 meseci
objDataAdapter = Nothing
objConnection = Nothing
objDataView = Nothing

tu ti je greska ti ponistis ta tri objekta i oni ti budu null u sledecem kliku. Nakon Else dodaj ponovo inicijalizaciju tih objekata npr objDataAdapter As New SqlDataAdapter
 
Odgovor na temu

brankec
Bosanski Brod

Član broj: 140157
Poruke: 161
*.teol.net.



Profil

icon Re: DataGridView problem24.03.2010. u 05:59 - pre 170 meseci
Hvala ti.
 
Odgovor na temu

malo_nj
novi sad

Član broj: 140825
Poruke: 104
213.196.121.*

Sajt: www.2advanced.com


Profil

icon Re: DataGridView problem24.03.2010. u 07:05 - pre 170 meseci
nema na cemu. mada danas prolazim kroz brod pa moze piva :)
 
Odgovor na temu

brankec
Bosanski Brod

Član broj: 140157
Poruke: 161
*.teol.net.



Profil

icon Re: DataGridView problem24.03.2010. u 09:41 - pre 170 meseci
Moze i gajba!
 
Odgovor na temu

[es] :: .NET :: DataGridView problem

[ Pregleda: 1864 | Odgovora: 6 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.