Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

New poster here so bear with me. I am doing a small customer registration/waiting list web app, and most of the program is running well except for one thing... adding data to SQL Server. I've tried everything and nothing works. This is basically my code:

<asp:SqlDataSource ID="SqlDataSource4" runat="server"
    ConnectionString="<%$ ConnectionStrings:CustMastTestConnectionString %>"
    InsertCommand="INSERT INTO [Turns2] ([CustNum]) VALUES (@CustNum)" >

    <InsertParameters>
        <asp:ControlParameter Name="CustNum" ControlID="txtInput" 
            PropertyName="Text" Type=String />
    </InsertParameters>
</asp:SqlDataSource>

Still... it isn't inserting any data at all. I am trying to see what could be wrong but I see nothing. Any help would be greatly appreciated.

UPDATE: THis is my current code for the button press. It seems good to me but it isn't inserting data. I also made sure the columns had enough characters, writable, added an auto increment, etc. I added an entry manually and it worked fine

Try
        Dim connectionString As String = "Data Source=servername;Initial Catalog=CustMast_Test;Integrated Security=True"
        Using cn As New SqlConnection(connectionString)


            cn.Open()

            Dim cmd As New SqlCommand()
            cmd.Parameters.AddWithValue("@AcctNum", txtInput.Text)
            cmd.CommandText = "INSERT INTO [Turns2] ([AcctNum]) VALUES (@AcctNum)"

            cmd.ExecuteNonQuery()
            cn.Close()

        End Using
    Catch

    End Try

Also tried without ExecuteNonQuery. What is wrong?

share|improve this question
What's triggering your insert? – Richard Mar 12 at 20:37
A button press. – Lord Relix Mar 12 at 20:39
1  
You'll need to give more information to go on. An SqlDataSource doesn't insert data by itself - show the code behind your button press which is being used to call it. When you say nothing works, do you get any errors? – Richard Mar 12 at 20:41
1  
To get the most out of SO your questions should show the code you currently have and the errors, if any, that you are receiving. The words "I've tried everything" and "nothing works" are by definition inaccurate and devoid of useful content. The question as is is missing the code that actually uses the sqldatasource and there are no error messages listed. – Chris Lively Mar 12 at 20:44
1  
slaps forehead It wasn't giving me any errors. It seems I didn't write the codeback in VB. Sorry, pretty new at ASP. On a second note I have no idea how to call the command. Do I just write a normal "SQL Conn" as one usually does in VB or do I call the SqlSource that is already in ASP? Thanks in advance – Lord Relix Mar 12 at 20:44
show 10 more comments

1 Answer

Is this issue solved? If not, it might be that your SQL Server connection property has autocommit turned off. If so, your insert is working and being instantly rolled back. No error, no foul. Also no data.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.