Question cant insert records to data base

Joined
Mar 25, 2009
Messages
23
Programming Experience
Beginner
hello
I added the following stored procedure to the data base , it adds a record to a table
---------------------------------------------
VB.NET:
ALTER PROCEDURE dbo.AddNewLabStoredProcedure 
	(
	@LabName as nvarchar(MAX),
	@LabSite as nvarchar(MAx),
	@LabSupervisor as nvarchar(MAX),
	@LabisActive as bit
	)
	
AS
            INSERT INTO Labs (LabName,LabSite,LabSupervisor,LabisActive)    
            values (@LabName,@LabSite,@LabSupervisor,@LabisActive)
RETURN
----------------------------------------------
it works fine if I excute it from the SQL Server
---------------------------------------------
then I wrote this code to call it from a vb.net application
------------------------------------------------------
VB.NET:
Private Sub AddLab()
        Dim nl As New AddLabDialog
        Dim result As DialogResult
        result = nl.ShowDialog
        If result = Windows.Forms.DialogResult.OK Then
            Dim constr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=true"
            Dim con As New System.Data.SqlClient.SqlConnection(constr)
            con.Open()
            Dim com As New System.Data.SqlClient.SqlCommand
            com.Connection = con
            com.CommandType = CommandType.StoredProcedure
            com.CommandText = "AddNewLabStoredProcedure"
            com.Parameters.AddWithValue("LabName", nl.LabName)
            com.Parameters.AddWithValue("LabSite", nl.LabSite)
            com.Parameters.AddWithValue("LabSupervisor", nl.LabSupervisor)
            com.Parameters.AddWithValue("LabisActive", nl.isActive)
            Dim AddedRows As Integer

            AddedRows = com.ExecuteNonQuery()
            If AddedRows = 0 Then
                ToolStripStatusLabel1.Text = "Error Occured"
            Else
                ToolStripStatusLabel1.Text = "done successfully"
            End If
            con = Nothing
            com = Nothing
        End If
        nl = Nothing

    End Sub
-------------------------------------------------

the code excutes fine , and the message of "done successfully" is displayed
But no records were added to the Data Base , is it a bug or what?
 
Last edited:
1. Please use CODE tags to make your post easier to read.

2. Try prefixing your parameter names with @, for example :-

VB.NET:
com.Parameters.AddWithValue("@LabName", nl.LabName)
 
We get asked this question nearly every day, no it's not a bug. I 100% guarantee it will be solved if you read the DNU link in my signature
 
Back
Top