-2

I want to add blood group in my table. It is only storing as "A" meanwhile I want to store data as "A+".

I am using store procedure.

ALTER PROCEDURE [dbo].[spInsertBloodGroup]


@ids as int,
@des as nvarchar(2000),
@abbri as nvarchar(2000),
@Datet as datetime

AS

Begin


insert into  tblbloodgroup(intSeqId,varDescription,varAbbrivation,dtCreationDate) 
values ( @ids ,@des ,@abbri ,@Datet)

meanwhile my input values are coming from C# file which are written as.

string recordSave = "spInsertBloodGroup'" + seqID+ "','" + Description + "','" + Name + "','" + dateModed + "'";
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Mansoor
  • 41
  • 11
  • so what is your question? How to adjust the SP for use with blood group??how to alter table? – lordkain Nov 19 '13 at 08:32
  • I want to insert data in form of "A+" or "B+" instead of only "A" or "B" – Mansoor Nov 19 '13 at 08:36
  • what is the bloodgroup column here? is it varAbbrivation? – Sudhakar Tillapudi Nov 19 '13 at 08:38
  • A sample of your recordSave string after the line you wrote in the would be nice. As @Sudhakar said, its difficult to tell which of your parameters represent what. – Todd Bowles Nov 19 '13 at 08:39
  • yes the varAbbrivation column is for bloodgroup in SQL and in C# the name paramater is for bloodgroup – Mansoor Nov 19 '13 at 08:40
  • *Abbreviation. I know that it seems such a small thing but I always worry about lack of care and attention when people can't spell the variable names correctly. I inherited a bunch of code recently where there is "Acutal" everywhere instead of "Actual". Needless to say, the codebase is wrong in every other sense also. – Moo-Juice Nov 19 '13 at 08:45
  • And what happened/didn't happen when you tried a value of "A+" in that `nvarchar(2000)` parameter? What is the size of that column? – Hans Kesting Nov 19 '13 at 08:48
  • Can you include some sample data? If the Name variable is a string, and contains the value "A+", I see no reason why the code that you have written wouldn't work. I mean, its not great code, but it looks functional. – Todd Bowles Nov 19 '13 at 08:49
  • @Mansoor: i think you misplaced single quote immediately after SP name try this => string recordSave = "spInsertBloodGroup '" + seqID+ "','" + Description + "','" + Name + "','" + dateModed + "'"; – Sudhakar Tillapudi Nov 19 '13 at 08:54

1 Answers1

0

Consider using an SqlCommand to call your stored procedure, instead of doing manual string concatenation.

var sp = new SqlCommand("spInsertBloodGroup", conn)
{
    CommandType = CommandType.StoredProcedure
};

sp.Parameters.Add("@ids", SqlDbType.Int, seqID);
sp.Parameters.Add("@des", SqlDbType.NVarChar, Description);
sp.Parameters.Add("@abbri", SqlDbType.NVarChar, Name);
sp.Parameters.Add("@Datet", SqlDbType.Int, dateModed);

sp.ExecuteNonQuery();

Although, I have to ask why you've created a stored procedure that mimics an insert statement? Why not just create an SqlCommand for the Insert and call it directly? Does the stored procedure do additional things that you aren't showing us?

Todd Bowles
  • 1,554
  • 15
  • 24