2011-09-19 59 views
0
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指令,但它仍然给我这个错误。我该怎么办 ?SQLCommand(找不到类型或名称,是否缺少任何指令)?

回答

3

你有一个错字有:

SqlCommand DataCommand = new SqlCommand(Command, DataConnection); 

的SqlCommand代替SqlCommand的

+0

呜是!谢谢 –

+0

用户登录失败。用户未与可信的SQL Server连接相关联。 –

+0

这是我得到的第二个错误 –

相关问题