SQL Insert query in C# ASP.NET verses C# Windows forms.

Hello,
Is there a difference between  a C# ASP.NET SQL insert query and a C# Windows Forms  insert query.  Below is my ASP.NET SQL Insert Query:
 
                                    mCommand.Parameters.AddWithValue("@CallDate", ReportData.CallDate);
                                    mCommand.Parameters.AddWithValue("@CallTime", ReportData.CallTime);
                                    mCommand.Parameters.AddWithValue("@CallNumber", ReportData.CallNumber);
                                    mCommand.Parameters.AddWithValue("@Narrative", ReportData.Narrative);
                                    mCommand.CommandText =
                                        "Insert INTO DataPreHospital (StudentID, CallDate, CallTime, ResponseType, CallNumber, CallType," +
                                        " CallDisposition, Age, Sex, Race, Weight, Phase, Status, " +
                                        " PrehospitalAgencyID, PrehospitalUnit, Narrative) Values (" +
                                        ReportData.StudentID + ",  @CallDate, @CallTime," +
                                        ReportData.ResponseType + ", @CallNumber, " +
                                        ReportData.PatientType + ", " +
                                        ReportData.CallDispositionID + ", " +
                                        ReportData.Age + ", " +
                                        ReportData.Sex + ", " +
                                        ReportData.Race + ", " +
                                        ReportData.Weight + "," +
                                        ReportData.Phase + "," +
                                        ReportData.Status + ", " +
                                        ReportData.PreHospitalAgenchyID + ", " +
                                        ReportData.PreHospitalUnit + ",@Narrative )";
                                    mCommand.ExecuteNonQuery();

I get---   Incorrect syntax near ','.     Inspecting the query string  prior to execution shows:  

Insert INTO DataPreHospital (StudentID, CallDate, CallTime, ResponseType, CallNumber, CallType, CallDisposition, Age, Sex, Race, Weight, Phase, Status,  PrehospitalAgencyID, PrehospitalUnit, Narrative) Values (3969,  @CallDate, @CallTime,0, @CallNumber, 0, 0, 0, 0, 0, 0,1,0, 6, 1234,@Narrative ) .
At breakpoint all  variables are correct.  This is exactly how I would expect it to appear in Windows Forms.

Now for the final insult:  I run the query in Management Studio and it performs without error.   Does ASP.NET require some variation in formatting the query?

Thanks,
Vaughn Whitehead
vaughnwhiteheadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongSoftware Team LeadCommented:
SQL generated looks ok, BUT make sure your parameter's values do not contain "empty" values as you're concatenate  the string.

hence, debug the values of:

ReportData.StudentID
ReportData.ResponseType
ReportData.PatientType
ReportData.CallDispositionID
ReportData.Age
ReportData.Sex
ReportData.Race
ReportData.Weight
ReportData.Phase
ReportData.Status
ReportData.PreHospitalAgenchyID
ReportData.PreHospitalUnit

* and make sure there's a non-empty value there.
* and if you're passing char values, pls add single quotes for your values, Or try parameterized it when necessary.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vaughnwhiteheadAuthor Commented:
Thought I had all my strings as parameters, but did not.  Paramatized the string and problem fixed.

Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.