Con risposta Read Data from Database to populate database

  • venerdì 9 marzo 2012 18:05
     
      Contiene codice

    I have 3 options for my radio buttons

    1=Commercial Invoice

    2=ProFormaInvoice

    3=Invoice

    I have a stored procedure that brings back the field "TypeofInvoice" with values of 1,2,3... How would i read this stored procedure and determine what radio button should be checked.

            If cboOrders.Text = "" Then
                MessageBox.Show("You must select invoiceID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
    
            End If
            mcommand.CommandText = "up_GetCustomerOrder"
            mcommand.CommandType = CommandType.StoredProcedure
            mcommand.CommandTimeout = 300
    
            'Set the parameter and push to the header 
            prmOrder.Direction = ParameterDirection.Input
    
            mcommand.Parameters("@invoiceID").Value = CInt(cboOrders.Text)
    
            ' Populate Header
            mReader = mcommand.ExecuteReader
            Do While mReader.Read
                cboCustomerID.Text = mReader("CompanyName").ToString
                txtAddress.Text = mReader("Address").ToString
                txtCity.Text = mReader("City").ToString
                txtRegion.Text = mReader("Region").ToString
                txtPostalCode.Text = mReader("PostalCode").ToString
                txtCountry.Text = mReader("Country").ToString
                txtPhone.Text = mReader("Phone").ToString
                txtFax.Text = mReader("Fax").ToString
                txtShipName.Text = mReader("ShipName").ToString
                txtShipAddress.Text = mReader("ShipAddress").ToString
                txtShipCity.Text = mReader("ShipCity").ToString
                txtShipRegion.Text = mReader("ShipRegion").ToString
                txtShipPostalCode.Text = mReader("ShipPostalCode").ToString
                txtShipCountry.Text = mReader("ShipCountry").ToString
                txtShipOther.Text = mReader("ShipOther").ToString
                txtShipName.Text = mReader("ShipName").ToString
                txtShipOther.Text = mReader("ShipOther").ToString
                txtShipPhone.Text = mReader("ShipPhone").ToString
                txtShipFax.Text = mReader("ShipFax").ToString
                txtRBIOrderNo.Text = mReader("RBIOrderNo").ToString
                txtCustOrderNo.Text = mReader("CustOrderNo").ToString
                txtInvoiceID.Text = mReader("InvoiceID").ToString
                cboTerms.Text = mReader("Terms").ToString
                TxtMemo.Text = mReader("Memo").ToString
                'Add Radio button Logic
            Loop
            mcommand.Cancel()
            mReader.Close()
            conn.Close()
        End Sub


Tutte le risposte

  • domenica 11 marzo 2012 06:06
     
      Contiene codice

    Just tell which value it is,and set RadioButton.Checked。Sample is this:

    'Suppose only one record……
    If (mReader.Read()) Then
       'Suppose RadioButton1,2,3 are on the same winform……
       (Form1.Controls["RadioButton"+mReader("TypeOfInvovince").ToString()] as RadioButton).Checked=True
    End If

       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

  • lunedì 12 marzo 2012 16:12
     
      Contiene codice

    The radio buttons are not populating does anyone have any advise that would help me get these radio buttons to populate reading the values from the databse

      ' Populate Header
            mReader = mcommand.ExecuteReader
            Do While mReader.Read
                cboCustomerID.Text = mReader("CompanyName").ToString
                txtAddress.Text = mReader("Address").ToString
                txtCity.Text = mReader("City").ToString
                txtRegion.Text = mReader("Region").ToString
                txtPostalCode.Text = mReader("PostalCode").ToString
                txtCountry.Text = mReader("Country").ToString
                txtPhone.Text = mReader("Phone").ToString
                txtFax.Text = mReader("Fax").ToString
                txtShipName.Text = mReader("ShipName").ToString
                txtShipAddress.Text = mReader("ShipAddress").ToString
                txtShipCity.Text = mReader("ShipCity").ToString
                txtShipRegion.Text = mReader("ShipRegion").ToString
                txtShipPostalCode.Text = mReader("ShipPostalCode").ToString
                txtShipCountry.Text = mReader("ShipCountry").ToString
                txtShipOther.Text = mReader("ShipOther").ToString
                txtShipName.Text = mReader("ShipName").ToString
                txtShipOther.Text = mReader("ShipOther").ToString
                txtShipPhone.Text = mReader("ShipPhone").ToString
                txtShipFax.Text = mReader("ShipFax").ToString
                txtRBIOrderNo.Text = mReader("RBIOrderNo").ToString
                txtCustOrderNo.Text = mReader("CustOrderNo").ToString
                txtInvoiceID.Text = mReader("InvoiceID").ToString
                cboTerms.Text = mReader("Terms").ToString
                txtMemo.Text = mReader("Memo").ToString
                txtFOB.Text = mReader("FOB").ToString
                txtDestination.Text = mReader("Destination").ToString
                txtOrderDate.Text = mReader("OrderDate").ToString   'Add Date Format
                txtShippedDate.Text = mReader("ShippedDate").ToString 'Add Date Format
            Loop
    
            'Add Radio button Logic
    
            Dim invType As Integer
            Do While invType = 0
                invType = mReader("TypeofInvoice")
                If invType = 1 Then
                    BtnCommercialInvoice.Checked = True
                    BtnProFormaInvoice.Checked = False
                    BtnInvoice.Checked = False
    
                End If
    
                If invType = 2 Then
                    BtnCommercialInvoice.Checked = False
                    BtnProFormaInvoice.Checked = True
                    BtnInvoice.Checked = False
                End If
    
    
                If invType = 3 Then
                    BtnCommercialInvoice.Checked = False
                    BtnProFormaInvoice.Checked = False
                    BtnInvoice.Checked = True
    
                End If
    
            Loop
            mcommand.Cancel()
            mReader.Close()
            conn.Close()
        End Sub

  • martedì 13 marzo 2012 01:03
     
     
    What do you mean by "the radio button cannot populate"?Please have a good debug to test what value your "invType" is? 

       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

  • martedì 13 marzo 2012 07:28
    Moderatore
     
     Con risposta
    Hi SBolton,
    You should not use the SqlDataReader (mReader) out of the Do while statement, otherwise you will get nothing.
    In addition, I think the code have some logical issue.  The last row of the result will overwrite the former rows.
    If you still have any doubt and concern about this issue, please let us know.
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

  • martedì 13 marzo 2012 14:09
     
      Contiene codice

    Ah ok I got it working 

    one thing I do not understand is when I format the date, and select another value from the combobox my entire form gets hung up.  Any suggestions on how to debug this?

     Private Sub cboOrders_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboOrders.TextChanged

    ..............

                txtFOB.Text = mReader("FOB").ToString
                txtDestination.Text = mReader("Destination").ToString
                'txtOrderDate.Text = mReader("OrderDate")  'Add Date Format
                'txtShippedDate.Text = mReader("ShippedDate") 'Add Date Format
    
                'txtOrderDate.Text = Format(mReader("OrderDate"), "Short Date")   'Add Date Format Dates get stuck when formatted
                'txtShippedDate.Text = Format(mReader("ShippedDate"), "Short Date") 'Add Date Format Dates get stuck when formatted
    
    
                ' --------Add Radio button Logic
    
                Dim invType As Integer
    
                invType = mReader("TypeofInvoice")
                If invType = 1 Then
                    BtnCommercialInvoice.Checked = True
                    BtnProFormaInvoice.Checked = False
                    BtnInvoice.Checked = False
    
                End If
    
                If invType = 2 Then
                    BtnCommercialInvoice.Checked = False
                    BtnProFormaInvoice.Checked = True
                    BtnInvoice.Checked = False
                End If
    
    
                If invType = 3 Then
                    BtnCommercialInvoice.Checked = False
                    BtnProFormaInvoice.Checked = False
                    BtnInvoice.Checked = True
    
                End If
            Loop
    

  • mercoledì 14 marzo 2012 01:18
     
     Con risposta
    You are using Text_Changed event,in my mind,this event—If you use it very frequently,it will cause the problem of that。You should change to a button's click and have a try with。

       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

  • mercoledì 14 marzo 2012 07:13
    Moderatore
     
     
    Hi SBolton,
    I agree with Wei_Dong. 
    Control.TextChanged Event Occurs when the Text property value changes, so each time you type any word in the TextBox, the code will query the database and then pass values.
    I think you should reconsider Do While statement. As I said, the code has some logical issue.  The last row of the result will overwrite the former rows and it decreases performance.
    In addition, to improve the performance of your Windows Forms applications and avoid UI hung up, you need multithreading.
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us