C#连接存储过程提示找不到表0
下面是sql server 2008的存储过程
程序代码:
USE [MENTOR] GO /****** Object: StoredProcedure [dbo].[ShowInfo] Script Date: 05/23/2017 20:50:30 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[ShowInfo] ( @Tables varchar(2000),--表名 @PrimaryKey varchar(500),--排序的字段名 @Sort varchar(500) = NULL,--待排序的字段名 @CurrentPage int = 1,--当前页数 @PageSize int = 5,--每页记录数 @Fields varchar(2000) = '*',--查询条件 @Filter varchar(1000) = NULL, @Group varchar(1000) = NULL ) AS /**//*默认排序*/ IF @Sort IS NULL OR @Sort = '' SET @Sort = @PrimaryKey DECLARE @SortTable varchar(1000) DECLARE @SortName varchar(1000) DECLARE @strSortColumn varchar(1000) DECLARE @operator char(2) DECLARE @type varchar(1000) DECLARE @prec int /**//*设定排序语句.*/ IF CHARINDEX('DESC',@Sort)>0 BEGIN SET @strSortColumn = REPLACE(@Sort, 'DESC', '') SET @operator = '<=' END ELSE BEGIN IF CHARINDEX('ASC', @Sort) = 0 print '1' print REPLACE(@Sort, 'ASC', '') SET @strSortColumn = REPLACE(@Sort, 'ASC', '') print @strSortColumn SET @operator = '>=' print @operator END IF CHARINDEX('.', @strSortColumn) > 0 BEGIN SET @SortTable = SUBSTRING(@strSortColumn, 0, CHARINDEX('.',@strSortColumn)) SET @SortName = SUBSTRING(@strSortColumn, CHARINDEX('.',@strSortColumn) + 1, LEN(@strSortColumn)) END ELSE BEGIN SET @SortTable = @Tables SET @SortName = @strSortColumn print @SortTable print @SortName END
程序代码:
public partial class Form1 : Form { int ToatalCountRecornd;//总记录数 int PageItem = 100;//每页显示的条数 int CurrentPage = 1;//当前页数 public Form1() { InitializeComponent(); } public void Form1_Load(object sender, EventArgs e) { Binddatawithpage(1); } private string strcon = @"server=.;database=MENTOR;uid=sa;pwd=sophianlove2600"; private string strproc = @"ShowInfo"; /// <summary> /// /// </summary> /// <param name="conn"></param> /// <param name="strProcedure"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> private DataTable getdata(string conn, string strProcedure, int pageIndex, int pageSize) { using (SqlConnection connetion = new SqlConnection(conn)) { SqlCommand command = new SqlCommand(strproc, connetion); = CommandType.StoredProcedure; //存储过程参数 command.Parameters.Add("@Tables", SqlDbType.VarChar, 255).Value = "MYINFO"; command.Parameters.Add("@PrimaryKey", SqlDbType.VarChar, 255).Value = "useid"; command.Parameters.Add("@Sort", SqlDbType.VarChar, 255).Value = "useid"; command.Parameters.Add("@Fields", SqlDbType.NVarChar, 1000).Value = "*"; command.Parameters.Add("@PageSize", SqlDbType.Int).Value = pageSize.ToString(); command.Parameters.Add("@CurrentPage", SqlDbType.Int).Value = pageIndex.ToString(); if (connetion.State != ConnectionState.Open) { connetion.Open(); } try { //填充数据 SqlDataAdapter da = new SqlDataAdapter(command); DataSet ds = new DataSet(); da.Fill(ds); //获取总记录数 ToatalCountRecornd = Convert.ToInt32(ds.Tables[0].Rows[0][0]); //返回数据集 return ds.Tables[0]; } catch (SqlException err) { MessageBox.Show(err.Message); return null; } finally { connetion.Close(); } } } /// <summary> /// /// </summary> /// <param name="INdex"></param> private void Binddatawithpage(int INdex) { toolStripTextBox1.Text = INdex.ToString(); dataGridView1.DataSource = getdata(strcon, strproc, INdex,100); toolStripLabel1.Text = ToatalCountRecornd.ToString() ; } }
刚开始执行几次正常,几次之后就提示找不到表0了。
想问一下为什么会突然找不到表0了?