Click here to Skip to main content
15,889,462 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: ASP.NET C# -STRING PROCESSING Pin
Richard Deeming9-Mar-17 1:15
mveRichard Deeming9-Mar-17 1:15 
QuestionError Inserting data - into the database. Pin
samflex6-Mar-17 3:28
samflex6-Mar-17 3:28 
AnswerRe: Error Inserting data - into the database. Pin
Richard MacCutchan6-Mar-17 5:36
mveRichard MacCutchan6-Mar-17 5:36 
GeneralRe: Error Inserting data - into the database. Pin
samflex6-Mar-17 6:19
samflex6-Mar-17 6:19 
GeneralRe: Error Inserting data - into the database. Pin
Richard MacCutchan6-Mar-17 6:25
mveRichard MacCutchan6-Mar-17 6:25 
GeneralRe: Error Inserting data - into the database. Pin
samflex6-Mar-17 7:01
samflex6-Mar-17 7:01 
AnswerRe: Error Inserting data - into the database. Pin
F-ES Sitecore7-Mar-17 0:52
professionalF-ES Sitecore7-Mar-17 0:52 
GeneralRe: Error Inserting data - into the database. Pin
samflex8-Mar-17 5:03
samflex8-Mar-17 5:03 
I am still pretty stumped by this issue.

I have moved past the initial problem.

Right now, when i run the app, it is inserting records to the database correctly.

However, this works for only one class.

When I add a second class or table, I start getting a very deceitful error message.

For instance, when I run the app with one class:

It works.

When I run the second class separately too, it works as well.

However, when I combine them which is the real intent of this project, I keep getting "parameter @name is required but not supplied"

I have tested the stored procedure that I am using in Sql Server Management Studio and it works fine.

There is one critical step that I am missing but not sure how to fix this. I wonder if it is not possible to have multiple INSERT statements using Ajax and webmethods.

Below is the code that I am currently using.

PHP
    <script type="text/javascript">
        $(document).ready(function () {
            $(document).on("click", "#empAdd", function () { //
                var rowCount = $('.data-contact-person').length + 1;
                var contactdiv = '<tr class="data-contact-personm">' +
                    '<td><input type="text" style="width:200px;" name="employeename' + rowCount + '" placeholder="Your name..." class="form-control employeename01" /></td>' +
                    '<td><input type="text" style="width:200px;" name="employeetitle' + rowCount + '" placeholder="Your title..." class="form-control employeetitle01" /></td>' +
                    '<td><input type="text" style="width:200px;" name="employeeemail' + rowCount + '" placeholder="Your email address..." class="form-control employeeemail01" /></td>' +
                    '<td style="width:200px;"><button type="button" id="empAdd" class="btn btn-xs btn-primary classAdd">Add More</button>' +
                    '<button type="button" id="empDeletem" class="deleteContact btn btn btn-danger btn-xs">Remove</button></td>' +
                    '</tr>';
                $('#emptable').append(contactdiv); // Adding these controls to Main table class
            });

            $(document).ready(function () {
                $(document).on("click", "#btnAdd", function () { //
                    var rowCount = $('.data-contact-person').length + 1;
                    var contactdiv = '<tr class="data-contact-person">' +
                        '<td><input type="text" style="width:200px;" name="sourcename' + rowCount + '" placeholder="Name of income source..." class="form-control sourcename01" /></td>' +
                        '<td><input type="text" style="width:200px;" name="sourceaddress' + rowCount + '" placeholder="Address of income source..." class="form-control sourceaddress01" /></td>' +
                        '<td><input type="text" style="width:200px;" name="sourceincome' + rowCount + '" placeholder="Income..." class="form-control sourceincome01" /></td>' +
                        '<td style="width:200px;"><button type="button" id="btnAdd" class="btn btn-xs btn-primary classAdd">Add More</button>' +
                        '<button type="button" id="btnDelete1" class="deleteContact btn btn btn-danger btn-xs">Remove</button></td>' +
                        '</tr>';
                    $('#maintable').append(contactdiv); // Adding these controls to Main table class
                });


                $(document).on("click", ".deleteContact", function () {
                    $(this).closest("tr").remove(); // closest used to remove the respective 'tr' in which I have my controls 
                });

                function getAllSourcepData() {
                    var data = [];
                    $('tr.data-contact-person').each(function () {
                        var ename = $(this).find('.employeename01').val();
                        var etitle = $(this).find('.employeetitle01').val();
                        var email = $(this).find('.employeeemail01').val();
                        var sname = $(this).find('.sourcename01').val();
                        var saddress = $(this).find('.sourceaddress01').val();
                        var sincome = $(this).find('.sourceincome01').val();
                        var alldata = {
                            'emplName': ename,
                            'emplTitle': etitle,
                            'empMail': email,
                            'mySource': sname,
                            'mySAddress': saddress,
                            'mySIncome': sincome
                        }
                        data.push(alldata);
                    });
                    console.log(data);
                    return data;
                }

                $("#btnSubmit").click(function () {
                    var data = JSON.stringify(getAllEmpData());
                    var data = JSON.stringify(getAllSourcepData());
                    console.log(data);
                    $.ajax({
                        url: 'disclosures.aspx/SaveData',
                        type: 'POST',
                        contentType: 'application/json; charset=utf-8',
                        data: JSON.stringify({ 'empdata': data }),
                        success: function () {
                            alert("Data Added Successfully");
                        },
                        error: function (xhr, status, error) {
                            alert(xhr.responseText);
                        }
                    });
                });
            });
        });
    </script>
<style type="text/css">
    .bs-example{
    	margin-left: 250px;
    	margin-top: 30px;
    }
</style>
</head>
<body> 
   <div class="bs-example"> 
    <form id="form1" runat="server">  
        <div class="container">  
            <table id="emptable">  
                <thead>  
                    <tr>  
                        <th>Employee Name</th>  
                        <th>Title</th>  
                        <th>Email</th>  
                    </tr>  
                </thead>  
                <tbody>  
                    <tr class="data-contact-person">  
                        <td>  
                            <input type="text" style="width:200px;" name="employeename" class="form-control employeename01" placeholder="Your name..." /></td>  
                        <td>  
                            <input type="text" style="width:200px;" name="employeetitle" class="form-control employeetitle01" placeholder="Your title..." /></td>  
                        <td>  
                            <input type="text" style="width:200px;" name="employeeemail" class="form-control employeeemail01" placeholder="Your email address..." /></td>  
                        <td>  
                        </td>  
                    </tr>  
                </tbody>  
            </table><br /><br />
            <table id="maintable">  
                <thead>  
                    <tr>  
                        <th>Name</th>  
                        <th>Address</th>  
                        <th>Income</th>  
                    </tr>  
                </thead>  
                <tbody>  
                    <tr class="data-contact-person">  
                        <td>  
                            <input type="text" style="width:200px;" name="sourcename" class="form-control sourcename01" placeholder="Name of income source..." /></td>  
                        <td>  
                            <input type="text" style="width:200px;" name="sourceaddress" class="form-control sourceaddress01" placeholder="Address of income source..." /></td>  
                        <td>  
                            <input type="text" style="width:200px;" name="sourceincome" class="form-control sourceincome01" placeholder="Income..." /></td>  
                        <td style="width:200px;">  
                            <button type="button" id="btnAdd" class="btn btn-xs btn-primary classAdd">Add More</button>  
                        </td>  
                    </tr>  
                </tbody>  
            </table><br /><br /> 
            <button type="button" id="btnSubmit" class="btn btn-primary btn-md pull-center btn-sm">Submit</button> 
        </div>  
    </form>  


Below is code behind:


PHP
    <WebMethod()> _
    Public Shared Function SaveData(empdata As String) As String
        Dim serializedData = JsonConvert.DeserializeObject(Of List(Of Employee))(empdata)

        Using con = New SqlConnection(Constr)
            If con.State = ConnectionState.Closed Then
                con.Open()
            End If
            For Each data As Employee In serializedData
                Using cmd = New SqlCommand("sprInsertDisclsosures")
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.AddWithValue("@ename", data.emplName)
                    cmd.Parameters.AddWithValue("@email", data.emplTitle)
                    cmd.Parameters.AddWithValue("@title", data.empMail)
                    cmd.Parameters.AddWithValue("@sname", data.mySource)
                    cmd.Parameters.AddWithValue("@saddress", data.mySAddress)
                    cmd.Parameters.AddWithValue("@sincome", data.mySIncome)
                    '  cmd.Parameters.AddWithValue("@CreatedDate", DateTime.Now)
                    cmd.Connection = con
                    cmd.ExecuteNonQuery()
                End Using
            Next
            con.Close()
        End Using
        Return Nothing
    End Function
End Class

Public Class Employee
    Public Property emplName() As String
        Get
            Return m_empName
        End Get
        Set(value As String)
            m_empName = value
        End Set
    End Property
    Private m_empName As String
    Public Property emplTitle() As String
        Get
            Return m_empTitle
        End Get
        Set(value As String)
            m_empTitle = value
        End Set
    End Property
    Private m_empTitle As String
    Public Property empMail() As String
        Get
            Return m_empMail
        End Get
        Set(value As String)
            m_empMail = value
        End Set
    End Property
    Private m_empMail As String
    Public Property mySource() As String
        Get
            Return m_mySource
        End Get
        Set(value As String)
            m_mySource = value
        End Set
    End Property
    Private m_mySource As String
    Public Property mySAddress() As String
        Get
            Return m_mySAddress
        End Get
        Set(value As String)
            m_mySAddress = value
        End Set
    End Property
    Private m_mySAddress As String
    Public Property mySIncome() As String
        Get
            Return m_mySIncome
        End Get
        Set(value As String)
            m_mySIncome = value
        End Set
    End Property
    Private m_mySIncome As String

GeneralRe: Error Inserting data - into the database. Pin
F-ES Sitecore8-Mar-17 5:44
professionalF-ES Sitecore8-Mar-17 5:44 
GeneralRe: Error Inserting data - into the database. Pin
samflex8-Mar-17 6:09
samflex8-Mar-17 6:09 
GeneralRe: Error Inserting data - into the database. Pin
F-ES Sitecore8-Mar-17 22:16
professionalF-ES Sitecore8-Mar-17 22:16 
GeneralRe: Error Inserting data - into the database. Pin
Richard Deeming8-Mar-17 7:58
mveRichard Deeming8-Mar-17 7:58 
GeneralRe: Error Inserting data - into the database. Pin
samflex8-Mar-17 8:40
samflex8-Mar-17 8:40 
GeneralRe: Error Inserting data - into the database. Pin
Richard Deeming8-Mar-17 8:50
mveRichard Deeming8-Mar-17 8:50 
GeneralRe: Error Inserting data - into the database. Pin
samflex8-Mar-17 8:55
samflex8-Mar-17 8:55 
GeneralRe: Error Inserting data - into the database. Pin
Richard Deeming8-Mar-17 9:09
mveRichard Deeming8-Mar-17 9:09 
GeneralRe: Error Inserting data - into the database. Pin
samflex8-Mar-17 9:19
samflex8-Mar-17 9:19 
Questioninput string was not in a correct format published site error when recycle working properly Pin
Praveen Kandari3-Mar-17 23:31
Praveen Kandari3-Mar-17 23:31 
AnswerRe: input string was not in a correct format published site error when recycle working properly Pin
Richard MacCutchan3-Mar-17 23:37
mveRichard MacCutchan3-Mar-17 23:37 
GeneralRe: input string was not in a correct format published site error when recycle working properly Pin
Praveen Kandari3-Mar-17 23:39
Praveen Kandari3-Mar-17 23:39 
GeneralRe: input string was not in a correct format published site error when recycle working properly Pin
EcareTechnologies8-Mar-17 20:11
EcareTechnologies8-Mar-17 20:11 
QuestionHow to remove marshaling errors for COM-interop or PInvoke Pin
Member 30804702-Mar-17 23:39
Member 30804702-Mar-17 23:39 
AnswerRe: How to remove marshaling errors for COM-interop or PInvoke Pin
Richard MacCutchan3-Mar-17 1:05
mveRichard MacCutchan3-Mar-17 1:05 
QuestionASP.net ajax image upload Pin
Member 130057291-Mar-17 6:15
Member 130057291-Mar-17 6:15 
AnswerRe: ASP.net ajax image upload Pin
F-ES Sitecore1-Mar-17 23:00
professionalF-ES Sitecore1-Mar-17 23:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.