using System;
using System.Data;
using System.Data.SqlClient;namespace ProDash
{
   public class Data
    {
       private SqlConnection SqlConnection1;
       private DataSql ds;       public Data()
       {
           SqlConnection conn = new SqlConnection("data source=.;uid=sa;pwd=sa;database=radb");
             }       public int Insert(string tbId, string tbName, string cobYype, string cobTime)
       {
           ds=new DataSql();
           int i = 0;
           SqlCommand InsertCom = new SqlCommand();
           try
           {
               InsertCom.CommandType = CommandType.Text;
             ds.InsertData(InsertCom,tbId,tbName,cobYype,cobTime);
               InsertCom.Connection = SqlConnection1;               SqlConnection1.Open();
               i = Convert.ToInt32(InsertCom.EndExecuteNonQuery());
               return i;
           }
           catch
           {
               throw;
           }
           finally
           {
               SqlConnection1.Close();
               InsertCom.Dispose();
           }
       }         }
}
运行提示:错误 1 “EndExecuteNonQuery”方法没有采用“0”个参数的重载 C:\Documents and Settings\6515b\桌面\临时文件\ProDash\ProDash\Data.cs 31 36 ProDash

解决方案 »

  1.   

     i = Convert.ToInt32(InsertCom.ExecuteNonQuery()); 
      

  2.   

    谢谢二三楼(*^__^*) 
    可以运行了,但是被catch throw了出来而且警告 从未对字段“ProDash.Data.SqlConnection1”赋值,字段将一直保持其默认值 null 接下来该怎么做呢?该给SqlConnection1赋什么呢?,我的Catch该怎么做呢?
      

  3.   

    我在public Data()
    {
    SqlConnection1 = new SqlConnection();
    }
    加了这句,然后就被throw 扔出来了
      

  4.   

      public class Data 
        { 
           private slqConnection con; 
           private sqlCommand InsertCom;
           private DataSql ds;        public Data() 
           { 
           }
           private void Getcon()
           {
               conn = new SqlConnection("data source=.;uid=sa;pwd=sa;database=radb"); 
               conn.open();
           }        public int Insert(string tbId, string tbName, string cobYype, string cobTime) 
           { 
               this.Getcon();
               ds=new DataSql(); 
               int i = 0; 
               InsertCom = new SqlCommand(); 
               try 
               { 
                   InsertCom.CommandType = CommandType.Text; 
                   ds.InsertData(InsertCom,tbId,tbName,cobYype,cobTime); 
                   InsertCom.Connection = con;  
                   i = InsertCom.ExecuteNonQuery();
                   return i; 
               } 
               catch 
               { 
                   throw; 
               } 
               finally 
               { 
                   InsertCom.Dispose();
                   con.Close();   
               } 
           } 
        } 呵呵,跟你把代码改动了一下,程序中有两个Sqlconnection对象,,,而命令行的对象指定的连接对象是SqlConnection1,而不是conn,释放资源是就出错了,还望指教
      

  5.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                SqlConnection cnn = new SqlConnection();
                cnn.ConnectionString = "Data Source=myserver;Initial Catalog=School;uid=sa;pwd=;";
                cnn.Open();
                int age=18;
                string sno = "060001";
                string sql = "Update Student Set 年龄=" + age + " Where 学号='" + sno + "'";
                SqlCommand cmd = new SqlCommand(sql, cnn);
                cmd.EndExecuteNonQuery();
            }
        }
    }错误 1 “EndExecuteNonQuery”方法没有采用“0”个参数的重载 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\WindowsApplication1\Form1.cs 28 13 WindowsApplication1
    帮帮我啊!
      

  6.   

    cmd.EndExecuteNonQuery()修改成cmd.ExecuteNonQuery();看看