How to insert and get .NET web-service data Object

2019-08-29 01:49发布

I have a web-service in .NET it's inserting and retrieving data's from database as object's.. I'll copy some part of web-service here..

   [WebMethod(Description = "This is used to insert details into sql server")]

    public string InsertDetails(DataTable myDetails, string STR1)
    {
        try
        {
            foreach (DataRow row in myDetails.Rows)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "dbo.InsertQry";
                cmd.Parameters.Add(new SqlParameter("@P_no", row["POD_Number"].ToString()));
                cmd.Parameters.Add(new SqlParameter("@P_id", STR1));
                cmd.Parameters.Add(new SqlParameter("@P_author", Convert.ToInt64(row["P_author"])));

                //opening the connection
                cmd.Connection = sqlCon;
                sqlCon.Open();
                int retValue = cmd.ExecuteNonQuery();
                sqlCon.Close();
                if (retValue == 0)
                    return "false";
            }
            return "true";
        }

        catch (Exception ex)
        {
            ErrorLogger(ex);
            return "false";
        }
    }

//-----------------------------------------------------------------------------------
[WebMethod(Description = "This is used to get details from sql server")]

    public DataSet GetDetails(string STR1)
    {
        DataSet ds = new DataSet();
        try
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "dbo.SelectQryFromDB";
            //opening the connection
            cmd.Connection = sqlCon;
            sqlCon.Open();
            ds.DataSetName = "myTbl";
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds,"myTbl");
            sqlCon.Close();
            return ds;
        }

        catch (Exception ex)
        {
            ErrorLogger(ex);
            ds.DataSetName = "Error";
            return ds;
        }
    }

//----------------------------

Any-one Help me by providing me the details how can i send those data's and retrieve data's in Android..This is my first application so i don't know much?? Please Provide me details so that i can insert and get data's using web-service??

I heard of kSOAP2 and i'm trying to accomplish this by using kSOAP2..

1条回答
对你真心纯属浪费
2楼-- · 2019-08-29 02:06

Working in Ksoap can be challenging sometimes. You first need to make sure your webservice is working fine and is giving you the proper result.

If that's done then you can consume the same from Android using ksoap library.

Here are few links that will help solve your problem:

1) How to call a local web service from Android mobile application will help you understand how you need to make a Ksoap call.

2) Inserting data into remote database from Android via ksoap

3) Returning data from server to Android

查看更多
登录 后发表回答