使用c#在asp.net中创建3层架构项目时DAL错误 [英] error in DAL in creating a 3-tier architecture project in asp.net using c#

查看:81
本文介绍了使用c#在asp.net中创建3层架构项目时DAL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#在3层架构上在asp.net中创建一个小项目。我想从Web表单向数据库发送七个参数。存储过程名称是spuserdetails,参数名称是name,age,add,phno,country,state,city。我的DAL代码如下:

i m creating a small project in asp.net using c# on 3-tier architecture. i want to send seven parameters from web form to database. stored proc name is spuserdetails and parameter name are name,age,add,phno,country,state,city. my DAL code is as follows:

namespace Datalgc
{       
    public class Class1
    {
        string connStr = ConfigurationManager.ConnectionStrings["spuserdetails"].ToString();
        public int Insert(string Name, DateTime DOB, string  Addr,int phno,string Country,string State,String City)
        {
            SqlConnection conn = new SqlConnection(spuserdetails);
            conn.Open();
            SqlCommand Cmd = new SqlCommand("InsertData", conn);
            Cmd.CommandType = CommandType.StoredProcedure;
            try
            {
                Cmd.Parameters.AddWithValue("@Name", Name);
                Cmd.Parameters.AddWithValue("@DOB", DOB);
                Cmd.Parameters.AddWithValue("@Addr", Addr);
                Cmd.Parameters.AddWithValue("@phno", phno);
                Cmd.Parameters.AddWithValue("@Country", Country);
                Cmd.Parameters.AddWithValue("@State", State);
                Cmd.Parameters.AddWithValue("@City", City);
                return Cmd.ExecuteNonQuery();
            }
            catch
            {
                throw;
            }
            finally
            {
                Cmd.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }
    }
}



语句


the statement

Cmd.CommandType = CommandType.StoredProcedure;

显示当前上下文中不存在命令类型。为什么?

shows that the commandtype does not exist in current context.why?

推荐答案

包含
Using System.Data

。这是此错误的常见原因。让我知道它是否无效。

at top of your code file.This is the common cause of this error.Let me know if it doesnt work.


这篇关于使用c#在asp.net中创建3层架构项目时DAL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆