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?