SQLCommand(找不到类型或名称。你是否缺少任何指令)?

时间:2011-09-19 16:23:36

标签: asp.net web-services sql-server-2005

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


namespace WcfService1
{
    /// <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
    {
        string Connection = "server=SHUMAILA-PC;  database=kse; Connect Timeout=10000";
        [WebMethod]
        public void SQLconn()
        {
            SqlConnection DataConnection = new SqlConnection(Connection);
            // the string with T-SQL statement, pay attention: no semicolon at the end of //the statement
            string Command = "INSERT INTO login VALUES (shumaila,mypassword)";
            // create the SQLCommand instance
            SQLCommand DataCommand = new SqlCommand(Command, DataConnection);
            // open the connection with our database
            DataCommand.Connection.Open();
            // execute the statement and return the number of affected rows
            int i = DataCommand.ExecuteNonQuery();
            //close the connection
            DataCommand.Connection.Close();  
        }

    }
}

我正在使用system.data.SqlClient指令,但它仍然给我这个错误。我该怎么办?

1 个答案:

答案 0 :(得分:3)

你有一个错字:

SqlCommand DataCommand = new SqlCommand(Command, DataConnection);

SqlCommand而不是SQLCommand