In Visual Studio 2013, I just want to pass data to sql table using VB?

I am developing an application which is my strong point, but now I need to code the back end. I am using Visual Studio 2013 with DevExpress and SQL Server 2014. This may be a simple question, but I have struggled to find a straightforward answer anywhere. I have an asp.net book but I still can't find the answer. I think I have hooked up my whole solution with a connection string to populate tables and stored procedures in my dataclass. I just want to add any user input to a table in SQL Server using a button with an onclick event. Of course it might not be that hard, but remember that I am a bit of a newbie, so any help would be greatly appreciated. If there are any questions you need to answer to help, let me know. I am writing in a VB script but am struggling to get it to work.Any advice will be taken into account. Thanks in advance!

     Protected Sub btnAddNewSource_Click(sender As System.Object, e As EventArgs) Handles btnAddNewSource.Click


    'ErrDetails.Text = ""
    'ErrDetails.Visible = False
    'FocusSet = False
    'errCount = 0
    'ErrDetails.Text = ""

    'If txtSourceFunding.Text = "" Then
    '    ErrDetails.Text = ErrDetails.Text + "Did you enter the funding source?" + vbNewLine
    '    ErrDetails.Visible = True
    '    txtSourceFunding.Focus()
    '    FocusSet = True
    '    errCount = errCount + 1
    'End If

    'If txtContributionFunding.Text = "" Then
    '    ErrDetails.Text = ErrDetails.Text + "Did you enter the contribution?" + vbNewLine
    '    ErrDetails.Visible = True
    '    txtContributionFunding.Focus()
    '    FocusSet = True
    '    errCount = errCount + 1
    'End If

    'If cmbStatus.Value = -1 Then
    '    ErrDetails.Text = ErrDetails.Text + "Did you inform us of the status?" + vbNewLine
    '    ErrDetails.Visible = True
    '    cmbStatus.Focus()
    '    FocusSet = True
    '    errCount = errCount + 1
    'End If

    'If FocusSet = True Then
    '    ErrDetails.ForeColor = Drawing.Color.Red
    '    ErrDetails.Height = 20 * errCount
    '    ErrDetails.Visible = True
    '    Return
    'End If

    'Dim btnSource = (From o In dc1.Update_GrantApplicationCycleFunding Where o.GrantApplicationID = Session("CurrentProjectID").ToString).FirstOrDefault
    'If Not IsNothing(btnSource) Then
    '    btnSource.GrantApplicationID = Session("CurrentProjectID")
    '    btnSource.GrantApplicationCycleFundingSource = txtSourceFunding.ToString
    '    btnSource.GrantApplicationCycleFundingContribution = txtContributionFunding.ToString
    '    btnSource.GrantApplicationCycleFundingStatusID = cmbStatus.ToString
    '    btnSource.GrantApplicationCycleFundingNotes = memFundingNotes.ToString

    'Else

    '    Dim NewGrantApplicationCycleFundings As New GrantApplicationCycleFunding
    '    With NewGrantApplicationCycleFundings
    '        .GrantApplicationID = Session("CurrentProjectID")
    '        .GrantApplicationCycleFundingSource = txtSourceFunding.ToString
    '        .GrantApplicationCycleFundingContribution = txtContributionFunding.ToString
    '        .GrantApplicationCycleFundingStatusID = cmbStatus.ToString
    '        .GrantApplicationCycleFundingNotes = memFundingNotes.Text
    '    End With
    '    dc1.GrantApplicationCycleFundings.InsertOnSubmit(NewGrantApplicationCycleFundings)
    '    dc1.SubmitChanges()
    '        End If

    'dc1.SubmitChanges()

      

+3


source to share


1 answer


Hey now I managed to make a button to add data to datagrid. The big thing I missed is the field value declarations at the bottom of the code and of course the data bindings! Never forget the correct DATABIND. You can adapt and use this in your own code if you have similar problems! If you need help or an explanation and I can help you, then I will. Just add a comment. Thanks to

    ** ErrDetails.Text = ""
    ErrDetails.Visible = False
    FocusSet = False
    errCount = 0
    ErrDetails.Text = ""

    If spnTotalEstimatedCost.Value <= 0 Then
        ErrDetails.Text = ErrDetails.Text + "Please enter the cost." + vbNewLine
        ErrDetails.Visible = True
        If FocusSet = False Then
            spnTotalEstimatedCost.Focus()
            FocusSet = True
        End If
        errCount = errCount + 1
    End If

    If txtSourceFunding.Text = "" Then
        ErrDetails.Text = ErrDetails.Text + "Please........?" + vbNewLine
        ErrDetails.Visible = True
        txtSourceFunding.Focus()
        FocusSet = True
        errCount = errCount + 1
    End If

    If spnContributionFunding.Value = 0 Then
        ErrDetails.Text = ErrDetails.Text + "Please......" + vbNewLine
        ErrDetails.Visible = True
        spnContributionFunding.Focus()
        FocusSet = True
        errCount = errCount + 1
    End If

    If FocusSet = True Then
        ErrDetails.ForeColor = Drawing.Color.Red
        ErrDetails.Height = 20 * errCount
        ErrDetails.Visible = True
        Return
    End If

    Dim NewGrantApplicationMatchFundings As New GrantApplicationMatchFunding
    With NewGrantApplicationMatchFundings
        .GrantApplicationID = Session("CurrentProjectID")
        .GrantApplicationMatchFundingName = txtSourceFunding.Text
        .GrantApplicationMatchFundingContribution = spnContributionFunding.Value
        .GrantApplicationMatchFundingStatus = cmbStatus.SelectedItem.Value
        .GrantApplicationMatchFundingNotes = memFundingNotes.Text
    End With
    dc1.GrantApplicationMatchFundings.InsertOnSubmit(NewGrantApplicationMatchFundings)
    dc1.SubmitChanges()
    'End If


    'dc1.SubmitChanges()

    txtSourceFunding.Text = ""
    spnContributionFunding.Value = ""
    cmbStatus.Value = ""
    memFundingNotes.Text = ""
    grdFunding.DataBind()

     Dim btnTotal = (From o In dc1.Select_GrantApplicationMatchFundingTotal(Session("CurrentProjectID").ToString)).FirstOrDefault
    If Not IsNothing(btnTotal) Then
        spnTotalMatchFunding.Text = btnTotal.TotalFunding
        txtGrantFunding.Text = (spnTotalMatchFunding.Value / spnTotalEstimatedCost.Value) * 100
    Else
        spnTotalMatchFunding.Text = 0
        txtGrantFunding.Text = 0
    End If

    Dim cafChange = (From o In dc1.GrantApplicationCostsAndFundings Where o.GrantApplicationID.ToString = Session("CurrentProjectID").ToString).FirstOrDefault
    If Not IsNothing(cafChange) Then
        cafChange.GrantApplicationID = Session("CurrentProjectID")
        cafChange.GrantApplicationProjectCostsYear1 = spnTotalEstimatedCost.Value
        cafChange.GrantApplicationMatchedFundingNotesYear1 = memNotesMatchFunding.Text
        cafChange.GrantApplicationProjectRequestedYear1 = txtGrantFunding.Value
        dc1.SubmitChanges()
    Else
        Dim NewGrantApplicationCostsAndFundings As New GrantApplicationCostsAndFunding
        With NewGrantApplicationCostsAndFundings
            .GrantApplicationID = Session("CurrentProjectID")
            .GrantApplicationProjectCostsYear1 = spnTotalEstimatedCost.Value
            .GrantApplicationMatchedFundingNotesYear1 = memNotesMatchFunding.Text
            .GrantApplicationProjectRequestedYear1 = txtGrantFunding.Value
        End With
        dc1.GrantApplicationCostsAndFundings.InsertOnSubmit(NewGrantApplicationCostsAndFundings)
        dc1.SubmitChanges()
    End If

      



End Sub

+1


source







All Articles