-1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.Common;
using System.Data;
using System.Data.SqlClient;

namespace modalwindow
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {
        [WebMethod]

        public  string SetConnectionString(string server, string database, string userId, string password)
        {

                string connectionString = string.Format("server={0}; uid={1}; pwd={2}; database={3}; MultipleActiveResultSets = true; enlist=false;Connection Timeout=10000000", server.Trim(), userId.Trim(), password.Trim(), database.Trim());
                return connectionString;    
        }


        public SqlConnection set (string connectionstring)
        {

            SqlConnection connection = new SqlConnection();

            if (connectionstring != "")
            {

                connection.ConnectionString = connectionstring;
                connection.Open();

            }

            if (connection.State != ConnectionState.Open)
            {
                connection.ConnectionString = connectionstring;
                connection.Open();
            }

          return connection;
        }

        public void CreateCommand(string constring,string commandtext,string commandtype)
        {
           SqlConnection con= set(constring);
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandTimeout = 1000000;
            cmd.CommandText=commandtext;
            if (commandtype == "StoredProcedure")
            {
                cmd.CommandType = CommandType.StoredProcedure;
            }
            else if (commandtype == "TableDirect")
            {
                cmd.CommandType = CommandType.TableDirect;
            }
            else
            {
                cmd.CommandType = CommandType.Text;
            }
        }



        [WebMethod]
        public string HelloWorld()
        {

            return "Hello World";
        }

        [WebMethod]
        public DataSet ExecuteFillDataSet(SqlCommand cmd)
        {
            DataSet dataSet = new DataSet();

            SqlDataAdapter dataAdapter = new SqlDataAdapter();

            dataAdapter.SelectCommand = cmd;

            CheckParams();

            dataAdapter.Fill(dataSet);

            return dataSet;
        }

        //[WebMethod]
        //public int ExecuteNonQuery(SqlCommand cmd)
        //{
        //    CheckParams();

        //    return cmd.ExecuteNonQuery();
        //}


        //[WebMethod]
        //public DbDataReader ExecuteReader(SqlCommand cmd)
        //{
        //    CheckParams();
        //    SqlDataReader reader=cmd.ExecuteReader();
        //    return reader;
        //}


        //[WebMethod]
        //public object ExecuteScalar(SqlCommand cmd)
        //{
        //    CheckParams();

        //    return cmd.ExecuteScalar();
        //}






        public SqlParameterCollection Parameters { get; set; }


        public SqlParameter AddParameter(string parameterName,SqlCommand cmd)
        {
            SqlParameter Parameter = cmd.CreateParameter();

            Parameter.ParameterName = parameterName;

            cmd.Parameters.Add(Parameter);

            return Parameter;
        }

        public SqlParameter AddParameter(string parameterName, object value,SqlCommand cmd)
        {
            SqlParameter dbParameter = AddParameter(parameterName,cmd);

            dbParameter.Value = value;

            return dbParameter;
        }





        private void CheckParams()
        {
            foreach (SqlParameter dbParameter in Parameters)
            {
                if (dbParameter.Value == null)
                {
                    dbParameter.Value = DBNull.Value;
                }

            }
        }







    }
}

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by stbuchok
1

From this point on, all posts you create that do not explain what you need and do not use the code tags will be flagged as a bad post. So far it just looks like you are trying to spam the forum.

My guess is once you have a certain number of posts you'll put a bunch of links to Viagra sites into your signature.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.