读书人

执行存储过程有关问题

发布时间: 2012-09-15 19:09:28 作者: rapoo

执行存储过程问题

C# code
using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString))        {            connection.Open();            //重新赋值SQL语句            //string storedStr = "Exec getxfjdkc @Tempxh='" + userName + "',@nd='" + nd + "',@jb='" + jb + "'";            string storedStr = "getxfjdkc";            SqlCommand command = new SqlCommand(storedStr, connection);            command.CommandType = CommandType.StoredProcedure;            command.CommandTimeout = 0;            command.Parameters.Add("@Tempxh",SqlDbType.VarChar);            command.Parameters.Add("@nd", SqlDbType.VarChar);            command.Parameters.Add("@jb", SqlDbType.VarChar);            command.Parameters["@Tempxh"].Value = userName;            command.Parameters["@nd"].Value = nd;            command.Parameters["@jb"].Value = jb;            int count = command.ExecuteNonQuery();            SqlDataAdapter adapter = new SqlDataAdapter(command);            DataSet dataSet = new DataSet();            adapter.Fill(dataSet);            DataTable table = dataSet.Tables[0];            foreach (DataRow row in table.Rows)            {                ResultIfo resultIfo = new ResultIfo();                resultIfo.SClass = Convert.ToString(row["kcdlmc"]);                resultIfo.SCode = Convert.ToString(row["kcbm"]);                resultIfo.Subject = Convert.ToString(row["kcmc"]);                resultIfo.Point = Convert.ToString(row["xf"]);                resultIfo.Result = Convert.ToString(row["cj"]);                resultIfo.InsSCode = Convert.ToString(row["tdkcbm"]);                resultIfo.InsSubject = Convert.ToString(row["tdkcmc"]);                resultIfo.InsPoint = Convert.ToString(row["tdxf"]);                resultIfo.InsResult = Convert.ToString(row["tdcj"]);                list.Add(resultIfo);            }}


上面的程序,执行了就会一直显示刷新的样子,但是没有数据,我在数据库里执行是可以找到数据的,我哪里写错了吗,求指导

[解决办法]
DataTable能取到料
[解决办法]
command.CommandTimeout = 0;这个改大点

读书人网 >C#

热点推荐