ricasss Posted October 18, 2012 at 03:34 PM Report #479636 Posted October 18, 2012 at 03:34 PM (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 October 18, 2012 at 03:42 PM by ricasss
ricasss Posted October 18, 2012 at 04:06 PM Author Report #479638 Posted October 18, 2012 at 04:06 PM 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
Guest Posted October 18, 2012 at 04:49 PM Report #479641 Posted October 18, 2012 at 04:49 PM 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.
Kline777 Posted October 19, 2012 at 08:18 AM Report #479688 Posted October 19, 2012 at 08:18 AM Ele por vezes faz isso... principalmente no load... em vez de enviar um erro para o utilizador simplesmente pára de executar o load e continua o programa..
ricasss Posted October 19, 2012 at 03:30 PM Author Report #479756 Posted October 19, 2012 at 03:30 PM Obrigado pelo esclarecimento 😉
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now