SQLCommand(找不到类型或名称。是否缺少任何指令)? 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用System.Web.Services; 使用系统数据; 使用System.Data.SqlClient; 命名空间WcfService1 { /// ///WebService 1的摘要说明 /// [WebService(命名空间=”http://tempuri.org/")] [WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] //要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。 //[System.Web.Script.Services.ScriptService] 公共类WebService 1:System.Web.Services.WebService { string Connection=“服务器=SHUMAILA-PC;数据库=kse;连接超时=10000”; [网络方法] 公共void SQLconn() { SqlConnection DataConnection=新的SqlConnection(连接); //带T-SQL语句的字符串,请注意://语句末尾没有分号 string命令=“插入登录值(shumaila,mypassword)”; //创建SQLCommand实例 SQLCommand-DataCommand=新的SQLCommand(Command,DataConnection); //打开与数据库的连接 DataCommand.Connection.Open(); //执行该语句并返回受影响的行数 int i=DataCommand.ExecuteOnQuery(); //关闭连接 DataCommand.Connection.Close(); } } }

SQLCommand(找不到类型或名称。是否缺少任何指令)? 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用System.Web.Services; 使用系统数据; 使用System.Data.SqlClient; 命名空间WcfService1 { /// ///WebService 1的摘要说明 /// [WebService(命名空间=”http://tempuri.org/")] [WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] //要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。 //[System.Web.Script.Services.ScriptService] 公共类WebService 1:System.Web.Services.WebService { string Connection=“服务器=SHUMAILA-PC;数据库=kse;连接超时=10000”; [网络方法] 公共void SQLconn() { SqlConnection DataConnection=新的SqlConnection(连接); //带T-SQL语句的字符串,请注意://语句末尾没有分号 string命令=“插入登录值(shumaila,mypassword)”; //创建SQLCommand实例 SQLCommand-DataCommand=新的SQLCommand(Command,DataConnection); //打开与数据库的连接 DataCommand.Connection.Open(); //执行该语句并返回受影响的行数 int i=DataCommand.ExecuteOnQuery(); //关闭连接 DataCommand.Connection.Close(); } } },asp.net,web-services,sql-server-2005,Asp.net,Web Services,Sql Server 2005,我正在使用system.data.SqlClient指令,但它仍然给我这个错误。我该怎么办?您的输入有误: 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 { /// &l

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

您的输入有误:

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();  
        }

    }
}

SqlCommand而不是SqlCommand

您的输入有误:

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();  
        }

    }
}

用户“”的SqlCommand而不是SqlCommand登录失败。用户未与受信任的SQL Server连接关联。@shumaila这是另一个问题-请检查以找到连接字符串的正确格式。用户“”的登录失败。用户未与受信任的SQL Server连接关联。@shumaila这是另一个问题-请检查以找到连接字符串的正确格式。