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
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
解决方案 »
- 关于mouse_down与timer的两个小问题
- 求最小生成树Prim()算法实现(用C#)
- .net如何利用session统一分配请求
- datagridview中空行的小问题<winform>
- 昨天程序还好的,今天就不正常了,急
- 从access表中筛选出一些数据的部分字段添加到另一个表做为备份,但有错误,请大家帮分析一下,谢谢!!!
- 如何在datasource设为dataview的datagrid里面删除选定的一行?
- 我对sql一个表保存,同时又要对别的一些表进行插入或更新操作
- 关于DirectInput的小疑惑
- SQL sever2008 R2 连 VS2013
- 水晶报表动态绑定数据问题
- 关于C# 正则转义的问题.
可以运行了,但是被catch throw了出来而且警告 从未对字段“ProDash.Data.SqlConnection1”赋值,字段将一直保持其默认值 null 接下来该怎么做呢?该给SqlConnection1赋什么呢?,我的Catch该怎么做呢?
{
SqlConnection1 = new SqlConnection();
}
加了这句,然后就被throw 扔出来了
{
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,释放资源是就出错了,还望指教
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
帮帮我啊!