3
Answers

Dataset return type

Photo of India Programmer

India Programmer

14y
12.4k
1

Hi all expert,

How to give message in method type dataset in web service. In else part of if I want to give some message like "Access is denied ". Here is my code. Pls help me.

[WebMethod, SoapHeader("spAuthenticationHeader")]   

    public DataSet GetCustList()

    {        

        if (spAuthenticationHeader.strUserName == "TestUser" && spAuthenticationHeader.strPassword == "TestPassword")

        {

            DataSet ds = new DataSet();

            CustomerDAL Customer = new CustomerDAL();

            return Customer.GetCustomer();

        }

        else

        {

            //string mymessage = "Access is Denied";           

            //DataSet ds1 = new DataSet();            

            Here i want to give message like ""Access is Denied";            

        }

       

    }


Answers (3)

0
Photo of Koteswararao Mallisetti
NA 1.1k 468.9k 14y
simply return null value in the else statement in the calling method compare the return value if is null give the access id denied message (or) you create the one dataset which contain the this error message as follows and return that value

 DataSet ds = new DataSet();
        DataTable dt = new DataTable("msg");
        DataColumn dc = new DataColumn("col1");
        dc.DataType = typeof(string);
        dc.ColumnName = "msg";
        dt.Columns.Add(dc);
        ds.Tables.Add(dt);
        DataRow dr = dt.NewRow();
        dr[0] = "Access is denied";
        ds.Tables["msg"].Rows.Add(dr);
        return ds;

Accepted
1
Photo of Ankur
NA 1.9k 438.8k 14y

Dear Indian Programmer,
try return Object type instead Dataset.
hope this would help.
Thanks and Regards
-2
Photo of Suthish Nair
NA 31.7k 4.6m 14y

Dear Indian Programmer,

Better update your name first, are you hiding from someone?