Hey guys, im trying to write to a table through a stored proc, i keep getting an error:
Procedure or function ParseTheString has too many arguments specified.
here is the simple code behind:
it is a text box and a button.
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=Matthew-PC\\SQLEXPRESS;Initial Catalog=SureViewDB;Integrated Security=True";
con.Open();
SqlCommand insertcmd = new SqlCommand("ParseTheString", con);
insertcmd.Parameters.Add("@AlarmID", SqlDbType.VarChar).Value = textBox1.Text;
insertcmd.Parameters.Add("@ServerNumber", SqlDbType.VarChar).Value = textBox1.Text;
insertcmd.CommandType = CommandType.StoredProcedure;
insertcmd.ExecuteNonQuery();
con.Close();
}
And here is the stored procedure running against data entered into text box:
CREATE PROCEDURE [dbo].[ParseTheString]
@Message VARCHAR(1000)
AS
BEGIN
DECLARE
@str1 VARCHAR(1),@str2 VARCHAR(250),@str3 VARCHAR(250),@str4 VARCHAR(250),
@str5 VARCHAR(250),@num1 INT,@num2 INT,@loop1 INT, @loop2 INT,@MType INT,
@str6 VARCHAR(25),@numstart int,@numend int,@now DATETIME
IF (NOT EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'LoggedMessages'
AND TABLE_SCHEMA = 'dbo'))
BEGIN
CREATE TABLE dbo.LoggedMessages (AlarmUnit INT Identity (1,1),ServerNo INT, AlarmID INT, GeneratedOn DATETIME, MessageType INT)
END
IF LOWER(LEFT(LTRIM(@Message),5)) = 'alarm'
BEGIN
SET @MType = 1
END
ELSE
BEGIN
SET @MType = 2
END
SET @loop1 = 1
SET @str1 = (SUBSTRING(@Message,@loop1,1))
WHILE ISNUMERIC(@str1)=0
BEGIN
SET @loop1 = @loop1 + 1
SET @str1 = (SUBSTRING(@Message,@loop1,1))
PRINT '@loop1a position = '+CAST(@loop1 AS VARCHAR(20))
END
SET @numstart = @loop1
SET @str1 = (SUBSTRING(@Message,@loop1,1))
WHILE ISNUMERIC(@str1)=1
BEGIN
SET @loop1 = @loop1 + 1
SET @str1 = (SUBSTRING(@Message,@loop1,1))
PRINT '@loop1 position = '+CAST(@loop1 AS VARCHAR(20))
END
SET @numend = @loop1
SET @num1 = (SELECT SUBSTRING(@Message,@numstart,(@numend-@numstart)))
PRINT @num1
SET @str1 = (SUBSTRING(@Message,@loop1,1))
WHILE ISNUMERIC(@str1)=0
BEGIN
SET @loop1 = @loop1 + 1
SET @str1 = (SUBSTRING(@Message,@loop1,1))
PRINT '@loop1a position = '+CAST(@loop1 AS VARCHAR(20))
END
SET @numstart = @loop1
SET @str1 = (SUBSTRING(@Message,@loop1,1))
WHILE ISNUMERIC(@str1)=1
BEGIN
SET @loop1 = @loop1 + 1
SET @str1 = (SUBSTRING(@Message,@loop1,1))
PRINT '@loop1a position = '+CAST(@loop1 AS VARCHAR(20))
END
SET @numend = @loop1
SET @num2 = (SELECT SUBSTRING(@Message,@numstart,(@numend-@numstart)))
PRINT @num2
SET @now = GETDATE()
IF @MType = 1
BEGIN
INSERT INTO dbo.LoggedMessages VALUES (@num1,@num2,@now,1)
END
ELSE
BEGIN
INSERT INTO dbo.LoggedMessages VALUES (@num2,@num1,@now,2)
END
END
in the text box i am simply typing in 'Alarm ID 6 has been received from video server number 1'
why is it giving the error?
is it because i am specifying the alarm id and servernum?
if so, how do i go about adding records through the sp?
any help is highly appreciated.