存储过程代码:CREATE PROCEDURE ShowCount
@Count INT OUTPUT
AS
SELECT @Count=COUNT(*) FROM Orders
GO
C#代码:SqlConnection sqlCon = new SqlConnection("Server=.;Initial Catalog=Northwind;Integrated Security=SSPI"); try
{
sqlCon.Open(); SqlCommand sqlCom = new SqlCommand();
sqlCom.CommandType = CommandType.StoredProcedure;
sqlCom.CommandText = "ShowCount";
sqlCom.Connection = sqlCon;
sqlCom.Parameters.Add(new SqlParameter("@Count", SqlDbType.Int));
sqlCom.Parameters["@Count"].Direction = ParameterDirection.Output; toolCount.Text = sqlCom.Parameters["@Count"].Value.ToString();
}
catch (Exception ex)
{
toolError.Text = ex.Message;
}
finally
{
sqlCon.Close();
}
出现错误提示:未将对象引用设置到对象的事例.
@Count INT OUTPUT
AS
SELECT @Count=COUNT(*) FROM Orders
GO
C#代码:SqlConnection sqlCon = new SqlConnection("Server=.;Initial Catalog=Northwind;Integrated Security=SSPI"); try
{
sqlCon.Open(); SqlCommand sqlCom = new SqlCommand();
sqlCom.CommandType = CommandType.StoredProcedure;
sqlCom.CommandText = "ShowCount";
sqlCom.Connection = sqlCon;
sqlCom.Parameters.Add(new SqlParameter("@Count", SqlDbType.Int));
sqlCom.Parameters["@Count"].Direction = ParameterDirection.Output; toolCount.Text = sqlCom.Parameters["@Count"].Value.ToString();
}
catch (Exception ex)
{
toolError.Text = ex.Message;
}
finally
{
sqlCon.Close();
}
出现错误提示:未将对象引用设置到对象的事例.
解决方案 »
- 求教一个关于C#和硬件通信的问题
- 求救!急!C# Object reference not set to an instance of an object.
- winform安装包问题
- gridview 里 dataformatstring 怎么设置才能让日期型字段 在gridview里 只显示年??
- 在VB中用variant能解决的,在C#中用object遇到问题
- 高手指点:如何读取app.config中的变量数据,不是在asp.net
- 求助一种容器
- 可以提供服务的网络对时IP和端口
- C# Directory Services 連接問題
- 问个delegate的问题
- 关于DevExpress.XtraCharts下的FullStackedBar3D控件使用
- 如何判断输入的字符是否需要转义?
{
sqlCon.Open(); SqlCommand sqlCom = new SqlCommand();
sqlCom.CommandType = CommandType.StoredProcedure;
sqlCom.CommandText = "ShowCount";
sqlCom.Connection = sqlCon;
sqlCom.Parameters.Add(new SqlParameter("@Count", SqlDbType.Int));
sqlCom.Parameters["@Count"].Direction = ParameterDirection.Output;
sqlCom.ExecuteNonQuery();
toolCount.Text = sqlCom.Parameters["@Count"].Value.ToString();
}
catch (Exception ex)
{
toolError.Text = ex.Message;
}
finally
{
sqlCon.Close();
}