陈斌彬的技术博客

Stay foolish,stay hungry

SQL Insert 多个字段

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace hx_tblSiteWebService
{
    /// <summary>
    /// WebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class WebService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public bool AddSiteInformation(bool IsAvailable, string SiteCode, string SiteName, string SiteAlias, string SiteY, string SiteX, string BaseStation, string Location, string Remark)
        {
            //连接SQL数据库
            System.Data.SqlClient.SqlConnection SqlCnn = new System.Data.SqlClient.SqlConnection("Data Source=192.168.1.90,1500;Initial Catalog=Asset;User ID=sa;Password=jsb@2015;");
            //打开数据库连接
            SqlCnn.Open();
            //加入SQL语句,实现数据库功能
            string sqlstr = "insert into hx_tblSite (CreateDate,IsAvailable,SiteCode,SiteName,SiteAlias,SiteY,SiteX,BaseStation,Location, Remark) values('" + DateTime.Now + " ','" + IsAvailable + "', '" + SiteCode + "', '" + SiteName + "', '" + SiteAlias + "', '" + SiteY + "', '" + SiteX + "', '" + BaseStation + "', '" + Location + "', '" + Remark + "')";
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.Connection = SqlCnn;
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.CommandText = sqlstr;
            //执行 
            cmd.ExecuteNonQuery();

            //关闭数据库
            SqlCnn.Close();

            return true;

        }


    }
}