C# 里用到的scalar variable

需要先定义,再使用:

                                   string testCase = rdr[0].ToString().Replace(prefix1, "").Replace(prefix2, "").Trim();
                                    string target = rdr[1].ToString().Trim();
                                    string device = rdr[3].ToString().Trim();
                                    string id = rdr[2].ToString().Trim();

                                    SqlParameter sqlp_Testcase = new SqlParameter("@testcase", testCase);
                                    SqlParameter sqlp_Device = new SqlParameter("@device", device.ToUpper());
                                    SqlParameter sqlp_Target = new SqlParameter("@target", target);
                                    SqlParameter sqlp_Id = new SqlParameter("@id", id);

                                    if (!string.IsNullOrEmpty(testCase))
                                    {
                                        string SQL_DelExistResults = "delete from [NTC].[dbo].[PMTestCase] where [Device] = @Device and [Name] = @testcase ";
                                        SqlHelper.ExecuteNonQuery(constr, CommandType.Text, SQL_DelExistResults, sqlp_Device, sqlp_Testcase);

                                        //Console.WriteLine("delete the same records from DB!");
                                       
                                        //string SQL_InsertPMTestcases = "insert into [NTC].[dbo].[PMTestCase] ([Name],[ID],[Target], [Device]) values ('" + testCase + "','" + id + "','" + target + "','" + device + "')";
                                        string SQL_InsertPMTestcases = "INSERT INTO [NTC].[dbo].[PMTestCase]([TestCaseID],[Name],[ID],[Target], [Device]) values"
                                           + "(newid(), @testcase, @id, @target, @device)";

                                        SqlHelper.ExecuteNonQuery(constr, CommandType.Text, SQL_InsertPMTestcases,
                                             sqlp_Testcase, sqlp_Id, sqlp_Target, sqlp_Device);
                                        Console.WriteLine(testCase + " : " + target);

                                     }

http://stackoverflow.com/questions/20330255/must-declare-the-scalar-variable-id-for-insert-parameter


发布了2 篇原创文章 · 获赞 0 · 访问量 3545
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览