如何在asp.net中实现Sql helper类

时间:2015-05-08 09:10:47

标签: asp.net ado.net

SqlHelper.ExecuteNonQuery(conString, CommandType.StoredProcedure, "UserRegister_Insert",
                        new SqlParameter("@firstname",SqlDbType.NVarChar,50),
                        new SqlParameter("@lastname",LastName),
                        new SqlParameter("@email",Email),
                        new SqlParameter("@password",Password),
                        new SqlParameter("@contactno",ContactNo));

我还实现了sql helper类,但该类的成员无法访问。

1 个答案:

答案 0 :(得分:1)

在当前上下文中未定义的连接字符串出错?
请使用字符串变量并在代码上方初始化它并尝试运行它

String conString=System.Configuration.ConfigurationManager.
    ConnectionStrings["connectionStringName"].ConnectionString;//your connection string name
SqlHelper.ExecuteNonQuery(conString, CommandType.StoredProcedure, "UserRegister_Insert",
                        new SqlParameter("@firstname",SqlDbType.NVarChar,50),
                        new SqlParameter("@lastname",LastName),
                        new SqlParameter("@email",Email),
                        new SqlParameter("@password",Password),
                        new SqlParameter("@contactno",ContactNo));