根据sessionid获取数据 [英] Getting data on the basess of sessionid

查看:123
本文介绍了根据sessionid获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于会话从数据库中获取数据.
但是却遇到了错误.

i am getting data from the database on the bases of session.
but getting the fallwoing error.

Error	6	A local variable named 'orderno' cannot be declared in this scope because it would give a different meaning to 'orderno', which is already used in a 'parent or current' scope to denote something else	





Error	7	Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?







<pre>public static string mymsg;
        public void GetInvoice(string orderno)
        {
            

            SqlConnection con = new SqlConnection();    //Create an SqlConnection object.

            //Pass the connection string to the SqlConnection object 

            con.ConnectionString = connectionString;

            con.Open();  //Open the connection 

            string procedureText = "GetInvoice";

            SqlCommand cmd = new SqlCommand(procedureText, con); //Create an SqlCommand object.

            cmd.CommandType = CommandType.StoredProcedure; //Change the behaviour of command text to stored procedure.
            string orderno = HttpContext.Current.Session["OrderID"]; //error line
            
            cmd.Parameters.Add(new SqlParameter("@OrderID", orderno));  //Pass value to the parameter that you have created in procedure.
            
            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                mymsg = "Thankyou " + dr["FirstName"].ToString() + " For Shopping with us. Your Order Number is:" + dr["OrderID"].ToString()+ "Please keep it for Corresponding with Us. Your Order will be Delivered Soon on ur  Given Address: "+dr["Address"].ToString();

                //Response.Write("<script>alert('Password is  :" + dr[0].ToString() + "')</script>");

            }

            else
            {

                Response.Write("<script>alert('User Name does not exist')</script>");

            }

            con.Close();




我将此功能称为




i call this function as

dbcon obj = new dbcon();

       try
       {


           if (obj.GetInvoice(Session["OrderID"]))
           {

               string MsgBody = dbcon.msgbody;
               //"using Gmail in ASP.NET";



我在响应时也出错.Write



i am also getting error on response.Write

推荐答案

您的错误很清楚.您无法理解的问题是什么?
好吧,您的第一个错误(错误6)表明您在范围内多次分配了"orderno"变量名.因此,请再次检查变量,并找到在其中分配了变量名称"orderno"的位置. VS之所以令人困惑,是因为它不知道要分配哪个数据..

您的第二个错误(错误7).您需要将变量转换为字符串.在发生异常的地方查找异常,并使用"ToString()"强制转换变量,它将解决您的问题.
Your errors are pretty clear. What''s the problem that you couldn''t understand?
Well your first error (Error 6) indicates that you have assigned the "orderno" variable name more than once in your scope. So check your variables again and find where you assigned a variable name "orderno". This confusing VS since it wont know which one to assign the data..

Your second error (Error 7). You need to cast the variable to string. Find the exception where it occurs and cast the variable by using "ToString()" it will fix your problems.


这篇关于根据sessionid获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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