Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate stored procedure to add with auto increment as its primary field?
    text
    copied!<p>I am trying to insert Data into my Sql-Server database though C#. I'm Calling a stored procedure and then would like it to add. I'm not sure what changes to make, but ultimately i would like it done in the stored procedure. </p> <p>My Stored procedure now:</p> <pre><code>CREATE PROCEDURE [dbo].[InsertTagProcdure] @TagID int, @Value nvarchar(200), @TagCount nvarchar(200) AS IF NOT EXISTS (SELECT NULL FROM Tag WHERE @TagID = @TagID) BEGIN INSERT INTO Tag (TagID,Value,TagCount) VALUES (@TagID,@Value,@TagCount) END </code></pre> <p>And my C# Code:</p> <pre><code>int TagID = int.Parse(txtTagID.Text); //This should fall away so auto increment. String Value = txtValue.Text; int TagCount = int.Parse(txtCount.Text); using (var conn = new SqlConnection(Properties.Settings.Default.DBConnectionString)) using (var cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "InsertTagProcdure"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@TagID", TagID); cmd.Parameters.AddWithValue("@Value", Value); cmd.Parameters.AddWithValue("@TagCount", TagCount); cmd.ExecuteNonQuery(); } </code></pre> <p>The Table Create i used: //Cant change this its what the boss gave me.</p> <pre><code>CREATE TABLE [dbo].[Tag]( [TagID] [int] IDENTITY(1,1) NOT NULL, [Value] [varchar](200) NOT NULL, [TagCount] [varchar](200) NULL, CONSTRAINT [PK_Tag] PRIMARY KEY CLUSTERED ( [TagID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload