Jump to content

Recommended Posts

Posted (edited)

Boas,

Estou com um problema um bocado estranho.

Cada vez que abro um formulário onde carrego as informações dos fornecedores da empresa onde trabalho, sempre que chega a uma determinada linha no evento Load() ele simplesmente para e abre o form sem executar o código que vem a seguir a essa linha.

Dim gCon As New SqlConnection(actConData)
	gCon.Open()

	Dim sqlComRead = New SqlCommand("Select * from T_Ent_SupTraAccounts Where ID=" & ID, gCon)
	Dim drSession = sqlComRead.ExecuteReader(CommandBehavior.Default)
	drSession.Read()
	Dim idowner As Integer = drSession("IDOwner").ToString
	txtAccountName.Text = drSession("Name").ToString
	If drSession("AccountType") = 2 Then
		rdbAccountSimple.Checked = True
		rdbAccountSpecial.Checked = False
	Else
		rdbAccountSpecial.Checked = True
		rdbAccountSimple.Checked = False
	End If
	chkValReem.Checked = drSession("vValReem")
	chkDevDoc.Checked = drSession("vValDevDoc")
	chkGrnSup.Checked = drSession("vValGrdSup")
	chSeguro.Checked = drSession("vSeguro")
	chTSeguro.Checked = drSession("vTSeguro")
	rdbSAPal.Checked = drSession("vPal")
	rdbSAVol.Checked = drSession("vVol")
	rdbSAKg.Checked = drSession("vKg")
	rdbNPrint.Checked = drSession("vServNPrint")
	rdbPrint.Checked = drSession("vServPrint")
	rdbExport.Checked = drSession("vServExpFile")
	chkImport.Checked = drSession("vServImpFile")
	chkVInvoice.Checked = drSession("vImpInvoice")
	chkTaxaUrg.Checked = drSession("vTaxaUrgencia")
	chkInterno.Checked = drSession("vInt")
	chkSerInt.Checked = drSession("vInternacional")
	'txtAccount.Text = drSession("NameAccount") 'PARA AQUI
	txtCode.Text = drSession("CodeAccount")
	txtContrato.Text = drSession("Contrato")
	Dim vTaxaFixa As Boolean = drSession("vTaxaFixa")
	If vTaxaFixa = False Then
		rdbCombKg.Checked = True
	Else
		rdbTaxa.Checked = True
	End If
	txtValorTaxaCombustivel.Text = drSession("ValorTaxaComb")
	Dim vAct As Boolean = drSession("vAct")

A linha onde para é a linha que esta comentada "txtAccount.Text = drSession("NameAccount")"

Esqueci-me de referir que antes funcionava correctamente, só depois de adicionar isto:

       txtAccount.Text = drSession("NameAccount")
    txtCode.Text = drSession("CodeAccount")
    txtContrato.Text = drSession("Contrato")
Edited by ricasss
Posted

Já consegui resolver

antes estava assim:

	    txtAccount.Text = drSession("NameAccount")
	    txtCode.Text = drSession("CodeAccount")
	    txtContrato.Text = drSession("Contrato")

E resolvi assim:

	    txtAccount.Text = drSession("NameAccount").ToString()
	    txtCode.Text = drSession("CodeAccount").ToString()
	    txtContrato.Text = drSession("Contrato").ToString()

Apenas adicionei .ToString() mas não consigo entender o porque...

Obrigado

Posted

txtAccount.Text está à espera que o valor atribuído seja uma string, e o valor retornado por drSession("...") certamente era um object.

O compilador do VB.Net por defeito, não se queixa das conversões entre tipos ao contrário do compilador de C# (mas podes desactivar isso nas opções do compilador).

Pessoalmente prefiro ser eu a fazer as conversões manualmente.

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.