-----创建的一个公共类using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;namespace StudentInfo.方法及类
{
public class Common
{
SqlConnection con = new SqlConnection();
SqlCommand com=new SqlCommand(); private void opcon()
{
con.ConnectionString = "server=(local);database=StudentInfo;integrated security=true";
con.Open();
} public void opencommand(string commtext,CommandType commtype,SqlParameter[] para)
{
opcon();
com.Connection = con;
com.CommandText=commtext;
com.CommandType=commtype; if(para!=null)
{
for (int i = 0; i < para.Length;i++ )
{
com.Parameters.Add(para[i]);
}
}
}
public DataSet fillData(string commtext,CommandType commtype, SqlParameter[] para)
{
opencommand(commtext,commtype,para);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
closecon();
return ds; } public int executeNuery(string commtext, CommandType commtype, SqlParameter[] para)
{
opencommand(commtext, commtype, para);
int i=com.ExecuteNonQuery();
closecon();
return i;
} private void closecon()
{
con.Close();
}
}
}
---创建的一个添加和查询方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Collections;namespace StudentInfo.方法及类
{
public class Func
{
Common CN = new Common();
public DataSet Look()
{
DataSet ds = CN.fillData("Look",CommandType.StoredProcedure,null);
return ds;
}
public int Addvalues(string N, string S, string B) { SqlParameter[] para = new SqlParameter[3];
para[0] = new SqlParameter("@Stu_name", SqlDbType.NVarChar, 20, "Stu_name");
para[0].Value = N;
para[1] = new SqlParameter("@Stu_sex", SqlDbType.NVarChar, 2, "Stu_sex");
para[1].Value = S;
para[2] = new SqlParameter("@Stu_birth", SqlDbType.DateTime, 100, "Stu_birth");
para[2].Value = DateTime.Parse(B);
int i = CN.executeNuery("addStudent", CommandType.StoredProcedure, para);
return i;
}
}
}为什么调用Addvalues出现下列的错:
过程 Look 没有参数,但却为该过程提供了参数。 我的储存过程是这样的:
USE [StudentInfo]
GO
/****** Object: StoredProcedure [dbo].[Look] Script Date: 11/23/2011 10:37:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[Look]
as
select*from StudentInfo
我很奇怪我没有带参数确报错说提供参数?
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;namespace StudentInfo.方法及类
{
public class Common
{
SqlConnection con = new SqlConnection();
SqlCommand com=new SqlCommand(); private void opcon()
{
con.ConnectionString = "server=(local);database=StudentInfo;integrated security=true";
con.Open();
} public void opencommand(string commtext,CommandType commtype,SqlParameter[] para)
{
opcon();
com.Connection = con;
com.CommandText=commtext;
com.CommandType=commtype; if(para!=null)
{
for (int i = 0; i < para.Length;i++ )
{
com.Parameters.Add(para[i]);
}
}
}
public DataSet fillData(string commtext,CommandType commtype, SqlParameter[] para)
{
opencommand(commtext,commtype,para);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
closecon();
return ds; } public int executeNuery(string commtext, CommandType commtype, SqlParameter[] para)
{
opencommand(commtext, commtype, para);
int i=com.ExecuteNonQuery();
closecon();
return i;
} private void closecon()
{
con.Close();
}
}
}
---创建的一个添加和查询方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Collections;namespace StudentInfo.方法及类
{
public class Func
{
Common CN = new Common();
public DataSet Look()
{
DataSet ds = CN.fillData("Look",CommandType.StoredProcedure,null);
return ds;
}
public int Addvalues(string N, string S, string B) { SqlParameter[] para = new SqlParameter[3];
para[0] = new SqlParameter("@Stu_name", SqlDbType.NVarChar, 20, "Stu_name");
para[0].Value = N;
para[1] = new SqlParameter("@Stu_sex", SqlDbType.NVarChar, 2, "Stu_sex");
para[1].Value = S;
para[2] = new SqlParameter("@Stu_birth", SqlDbType.DateTime, 100, "Stu_birth");
para[2].Value = DateTime.Parse(B);
int i = CN.executeNuery("addStudent", CommandType.StoredProcedure, para);
return i;
}
}
}为什么调用Addvalues出现下列的错:
过程 Look 没有参数,但却为该过程提供了参数。 我的储存过程是这样的:
USE [StudentInfo]
GO
/****** Object: StoredProcedure [dbo].[Look] Script Date: 11/23/2011 10:37:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[Look]
as
select*from StudentInfo
我很奇怪我没有带参数确报错说提供参数?
解决方案 »
- Excel进程关闭的问题
- 学习LinQ时候在MSDN网站上发现的疑问,为什么只提供英文还有日文版本的下载呢?
- .net 2.0的验证控件在本地没问题
- Image控件的使用问题!
- 学完了C#该如何继续ASP。NET
- 象MSN SPACE 那种允许自由拖放模块,采用的什么技术
- 怎样删除DataGrid中的一行或多行。用DeleteCommand事件怎样写?
- DataGrid中模板列提取系统时间的问题
- DataGrid绑定模板列出问题,服务器标记的格式不正确。
- 如何把用户在浏览网页时选择的内容提交到服务器?
- GridView选中,编辑,取消,删除总是出错求高手解答!
- 大家有没么有好的 dropdownlist 样式 拿出来秀一下
Addvalues里边传参了