Jump to content
PauloFMarques

Object reference

Recommended Posts

PauloFMarques

Bom dia.

Estou a criar um programa para o meu estágio, que envolve vb e sql(pois contem uma base de dados).

O programa tem corrido bem, mas hoje quando o abri apareceu-me este erro "An error occurred creating the form. See Exception.InnerExcreption for details. The error is: Format of the initialization string does not conform to specification starting ate index 155"

Já pesquisei na net e não encontrei nada que me ajudasse a entender o que se passa.

Alguém me pode ajudar??

Desde já obrigado.

PauloMarques


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
ribeiro55

Alguma coisa correu mal com uma string qualquer no designer do form.

Mete aqui a InnerException que te dá para vermos se detectamos algo que possas alterar no designer.


Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Share this post


Link to post
Share on other sites
PauloFMarques

E como faço isso??

É que ainda sou um bocado begginer nisto..


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
ribeiro55

Vamos fazer de outra maneira.

Podes disponibilizar o designer?

Na pasta do teu projecto, deverá ter o nome do form com ".designer.vb" à frente.


Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Share this post


Link to post
Share on other sites
PauloFMarques

São 11 ao todo, pois contem diferentes forms.

Queres só 1?


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
ribeiro55

O que rebenta.

Fecha os tabs todos e vai tentando abrir forms até que rebente.


Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Share this post


Link to post
Share on other sites
PauloFMarques

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim Nome_loginLabel As System.Windows.Forms.Label
        Dim PasswordLabel As System.Windows.Forms.Label
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.Button3 = New System.Windows.Forms.Button()
        Me.PasswordTextBox = New System.Windows.Forms.TextBox()
        Me.UtilizadoresBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.Db_gelpeixeDataSet = New Gelpeixe.db_gelpeixeDataSet()
        Me.Nome_loginTextBox = New System.Windows.Forms.TextBox()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.UtilizadoresTableAdapter = New Gelpeixe.db_gelpeixeDataSetTableAdapters.utilizadoresTableAdapter()
        Me.TableAdapterManager = New Gelpeixe.db_gelpeixeDataSetTableAdapters.TableAdapterManager()
        Me.Button4 = New System.Windows.Forms.Button()
        Nome_loginLabel = New System.Windows.Forms.Label()
        PasswordLabel = New System.Windows.Forms.Label()
        Me.GroupBox1.SuspendLayout()
        CType(Me.UtilizadoresBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Db_gelpeixeDataSet, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Nome_loginLabel
        '
        Nome_loginLabel.AutoSize = True
        Nome_loginLabel.Location = New System.Drawing.Point(21, 26)
        Nome_loginLabel.Name = "Nome_loginLabel"
        Nome_loginLabel.Size = New System.Drawing.Size(100, 13)
        Nome_loginLabel.TabIndex = 0
        Nome_loginLabel.Text = "Nome  de utilizador:"
        '
        'PasswordLabel
        '
        PasswordLabel.AutoSize = True
        PasswordLabel.Location = New System.Drawing.Point(27, 52)
        PasswordLabel.Name = "PasswordLabel"
        PasswordLabel.Size = New System.Drawing.Size(56, 13)
        PasswordLabel.TabIndex = 2
        PasswordLabel.Text = "Password:"
        '
        'GroupBox1
        '
        Me.GroupBox1.BackColor = System.Drawing.Color.Transparent
        Me.GroupBox1.Controls.Add(Me.Button3)
        Me.GroupBox1.Controls.Add(PasswordLabel)
        Me.GroupBox1.Controls.Add(Me.PasswordTextBox)
        Me.GroupBox1.Controls.Add(Nome_loginLabel)
        Me.GroupBox1.Controls.Add(Me.Nome_loginTextBox)
        Me.GroupBox1.Location = New System.Drawing.Point(224, 41)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(236, 110)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Login"
        '
        'Button3
        '
        Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.Button3.Location = New System.Drawing.Point(127, 81)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(75, 23)
        Me.Button3.TabIndex = 4
        Me.Button3.Text = "Login"
        Me.Button3.UseVisualStyleBackColor = True
        '
        'PasswordTextBox
        '
        Me.PasswordTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.UtilizadoresBindingSource, "password", True))
        Me.PasswordTextBox.Location = New System.Drawing.Point(127, 49)
        Me.PasswordTextBox.Name = "PasswordTextBox"
        Me.PasswordTextBox.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.PasswordTextBox.Size = New System.Drawing.Size(100, 20)
        Me.PasswordTextBox.TabIndex = 3
        Me.PasswordTextBox.UseSystemPasswordChar = True
        '
        'UtilizadoresBindingSource
        '
        Me.UtilizadoresBindingSource.DataMember = "utilizadores"
        Me.UtilizadoresBindingSource.DataSource = Me.Db_gelpeixeDataSet
        '
        'Db_gelpeixeDataSet
        '
        Me.Db_gelpeixeDataSet.DataSetName = "db_gelpeixeDataSet"
        Me.Db_gelpeixeDataSet.EnforceConstraints = False
        Me.Db_gelpeixeDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'Nome_loginTextBox
        '
        Me.Nome_loginTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.UtilizadoresBindingSource, "nome_login", True))
        Me.Nome_loginTextBox.Location = New System.Drawing.Point(127, 23)
        Me.Nome_loginTextBox.Name = "Nome_loginTextBox"
        Me.Nome_loginTextBox.Size = New System.Drawing.Size(100, 20)
        Me.Nome_loginTextBox.TabIndex = 1
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(12, 41)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(75, 23)
        Me.Button2.TabIndex = 4
        Me.Button2.Text = "utilizador"
        Me.Button2.UseVisualStyleBackColor = True
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(12, 12)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(75, 23)
        Me.Button1.TabIndex = 3
        Me.Button1.Text = "admin"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'UtilizadoresTableAdapter
        '
        Me.UtilizadoresTableAdapter.ClearBeforeFill = True
        '
        'TableAdapterManager
        '
        Me.TableAdapterManager.acessoTableAdapter = Nothing
        Me.TableAdapterManager.BackupDataSetBeforeUpdate = False
        Me.TableAdapterManager.cabosTableAdapter = Nothing
        Me.TableAdapterManager.computadoresTableAdapter = Nothing
        Me.TableAdapterManager.diversosTableAdapter = Nothing
        Me.TableAdapterManager.funcionarioTableAdapter = Nothing
        Me.TableAdapterManager.impressoraTableAdapter = Nothing
        Me.TableAdapterManager.ligacaoTableAdapter = Nothing
        Me.TableAdapterManager.monitorTableAdapter = Nothing
        Me.TableAdapterManager.officeTableAdapter = Nothing
        Me.TableAdapterManager.sistopeTableAdapter = Nothing
        Me.TableAdapterManager.softwareTableAdapter = Nothing
        Me.TableAdapterManager.UpdateOrder = Gelpeixe.db_gelpeixeDataSetTableAdapters.TableAdapterManager.UpdateOrderOption.InsertUpdateDelete
        Me.TableAdapterManager.utilizadoresTableAdapter = Me.UtilizadoresTableAdapter
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(591, 12)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(75, 23)
        Me.Button4.TabIndex = 5
        Me.Button4.Text = "Créditos"
        Me.Button4.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.BackgroundImage = Global.Gelpeixe.My.Resources.Resources.logo
        Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch
        Me.ClientSize = New System.Drawing.Size(678, 656)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.GroupBox1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "Form1"
        Me.Text = "Gelpeixe"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        CType(Me.UtilizadoresBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Db_gelpeixeDataSet, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Db_gelpeixeDataSet As Gelpeixe.db_gelpeixeDataSet
    Friend WithEvents UtilizadoresBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents UtilizadoresTableAdapter As Gelpeixe.db_gelpeixeDataSetTableAdapters.utilizadoresTableAdapter
    Friend WithEvents TableAdapterManager As Gelpeixe.db_gelpeixeDataSetTableAdapters.TableAdapterManager
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents PasswordTextBox As System.Windows.Forms.TextBox
    Friend WithEvents Nome_loginTextBox As System.Windows.Forms.TextBox
    Friend WithEvents Button4 As System.Windows.Forms.Button

End Class

Fui buscar uma versão anterior, e apareceu outro erro, ou seja, em vez de aparecer o erro de abertura dos forms,  aparece o seguinte[Login Failed for user".]


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
ribeiro55

Pois, é natural que os databinders tentem ligar a qualquer coisa @ design time.

O mais certo é alguma coisa ter acontecido à ligação com a tua base de dados, fora isso, o designer parece ok.


Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Share this post


Link to post
Share on other sites
PauloFMarques

Eu tinha a connectionstring assim:

 "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\geral\Desktop\2011-Database\Gelpeixe\Gelpeixe\db_gelpeixe.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

E uma stora minha aconselhou-me a por assim:

 Dim str As String = Directory.GetCurrentDirectory & "\Db_gelpeixe.mdf"
    Dim conexao As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='" & str & "';Integrated Security=True;Connect Timeout=30;User Instance=True'")

Será por isso??


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
ribeiro55

Como a tua professora recomendou é que está correcto, pois garante que a base de dados seja alcançada independentemente da máquina onde corre.

Pode é não estar a ser correctamente formatado, basta dares uma espreitadela à variável str antes de ser usada na ligação.

Para além disto, o último erro indica outra coisa: indica que tens de explicitar um username e password pois parece que a base de dados assim o exige.


Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Share this post


Link to post
Share on other sites
PauloFMarques

A base de dados foi criada sem ser necessário password ou utilizador.

Mas já está resolvido.

O erro estava na escrita da segunda forma

Directory.GetCurrentDirectory & "\Db_gelpeixe.mdf"
Dim conexao As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='" & str & "';Integrated Security=True;Connect Timeout=30;User Instance=True'")

Instance=True'") -> tem uma ' a mais.

De qualquer maneira, muito obrigado pela ajuda. ;)


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
PauloFMarques

De volta às duvidas, depois de corrigidos os erros anteriores surgiu-me o seguinte, a abrir um dos meus forms aparece o seguinte erro [Object reference not set to an instance of an object].

E a abrir outro form aparece [Format of initialization string does not conform to specification starting at index 0]

Desde já obrigado.

PauloMarques


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
Caça

O primeiro erro ocorre quando estás a usar propriedades de um objecto quando ele e "Nothing"

O segundo erro é de formatação

Mostra o código


Pedro Martins

Não respondo a duvidas por PM

Share this post


Link to post
Share on other sites
PauloFMarques

Para o primeiro erro utilizo o seguinte código:

 Private Sub RelatóriosPersonalizadosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RelatóriosPersonalizadosToolStripMenuItem.Click
        relatorios_personalizados.Show()
    End Sub

Para o segundo utilizo este:

Private Sub InserirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InserirToolStripMenuItem.Click
        inserir_dados.Show()
    End Sub


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
Caça

O erro deve estar no evento Load desses dois formulários, mostra o código de ambos


Pedro Martins

Não respondo a duvidas por PM

Share this post


Link to post
Share on other sites
PauloFMarques

Load do form onde tenho os botoes:

 Private Sub menu_administrador_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.utilizadores' table. You can move, or remove it, as needed.
        Me.UtilizadoresTableAdapter.Fill(Me.Db_gelpeixeDataSet.utilizadores)
        GroupBox1.Hide()
    End Sub

Não tenho load no form do primeiro erro.

Do segundo erro o Load é:

 Private Sub inserir_dados_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.ligacao' table. You can move, or remove it, as needed.
        Me.LigacaoTableAdapter.Fill(Me.Db_gelpeixeDataSet.ligacao)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.office' table. You can move, or remove it, as needed.
        Me.OfficeTableAdapter.Fill(Me.Db_gelpeixeDataSet.office)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.sistope' table. You can move, or remove it, as needed.
        Me.SistopeTableAdapter.Fill(Me.Db_gelpeixeDataSet.sistope)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.software' table. You can move, or remove it, as needed.
        Me.SoftwareTableAdapter.Fill(Me.Db_gelpeixeDataSet.software)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.cabos' table. You can move, or remove it, as needed.
        Me.CabosTableAdapter.Fill(Me.Db_gelpeixeDataSet.cabos)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.funcionario' table. You can move, or remove it, as needed.
        Me.FuncionarioTableAdapter.Fill(Me.Db_gelpeixeDataSet.funcionario)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.diversos' table. You can move, or remove it, as needed.
        Me.DiversosTableAdapter.Fill(Me.Db_gelpeixeDataSet.diversos)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.impressora' table. You can move, or remove it, as needed.
        Me.ImpressoraTableAdapter.Fill(Me.Db_gelpeixeDataSet.impressora)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.monitor' table. You can move, or remove it, as needed.
        Me.MonitorTableAdapter.Fill(Me.Db_gelpeixeDataSet.monitor)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.monitor' table. You can move, or remove it, as needed.
        Me.MonitorTableAdapter.Fill(Me.Db_gelpeixeDataSet.monitor)
        'TODO: This line of code loads data into the 'Db_gelpeixeDataSet.computadores' table. You can move, or remove it, as needed.
        Me.ComputadoresTableAdapter.Fill(Me.Db_gelpeixeDataSet.computadores)
    End Sub


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
Caça

Existe qualquer coisa de errado no teu DataSet


Pedro Martins

Não respondo a duvidas por PM

Share this post


Link to post
Share on other sites
PauloFMarques

O segundo erro está corrigido, era a declaração de variaveis que estava a alterar tudo.

Resta-me agora conseguir resolver o primeiro, ou seja, o [Object reference not set to an instance of an object].


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
Caça

Sabes utilizar BreakPoints?

Se sim coloca um lo load do form para ver se é o Dataset ou se é a GroupBox que está a "Nothing"

Se não, tira a primeira linha de código e testa, se der erro, o erro está na GroupBox, se não der o erro provavelmente esta no DataSet. E testa também sem código no load.


Pedro Martins

Não respondo a duvidas por PM

Share this post


Link to post
Share on other sites
PauloFMarques

Testei das duas formas, o dataset está bem, e a groupbox não esta "Nothing", exprimentei apagar as linhas, e deu erro das tres vezes, ou seka, quando tirei a linha do fill, quando tirei a da groupbox, e quando tirei as duas.


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
Caça

Substitui

relatorios_personalizados.Show()

por

Dim F as new relatorios_personalizados
F.Show()


Pedro Martins

Não respondo a duvidas por PM

Share this post


Link to post
Share on other sites
PauloFMarques

Isso resultou, obrigado.

Agora apareceu o mesmo erro, mas já no form dos relatorios_presonalizados, numa variavel que eu criei, mas diz que esta está "Nothing", qual é a razao para isso?

O codigo está aqui:

 Dim str As String = Directory.GetCurrentDirectory & "\Db_gelpeixe.mdf"
    Dim conexao As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='" & str & "';Integrated Security=True;Connect Timeout=30;User Instance=True")
    Dim cmdcomputador As New SqlCommand("select id_computadores, uso, n_func, data_compra, valor_s_iva, valor_seguro from computadores", conexao)
    Dim dacomputador As New SqlDataAdapter(cmdcomputador)
   Dim ds As New DataSet()
    Dim registo As Integer
Dim computadores_seguro As String = ds.Tables("computadores").Rows(registo).Item("valor_seguro")


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites
Caça

Flata ai isto

dacomputador.Fill(Ds, "Nomedatabela")

coloca depois de

Dim ds As New DataSet()


Pedro Martins

Não respondo a duvidas por PM

Share this post


Link to post
Share on other sites
PauloFMarques

Era isso mesmo que estava a faltar,muito obrigado. ;)


--Sometimes, we do what we want, but we don't want what we have done--

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.