ExecuteNonQuery:CommandText属性尚未初始化 [英] ExecuteNonQuery: CommandText property has not been initialized

查看:1116
本文介绍了ExecuteNonQuery:CommandText属性尚未初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为sampleproc的存储过程,它接受一个参数@rollno。

我试图运行下面的代码,但是它给出了错误:

I have a stored procedure named "sampleproc" that accepts one parameter @rollno.
I am trying to run the below code but it is giving the error:

<br />
"ExecuteNonQuery: CommandText property has not been initialized".





< strike> PLZ帮助我尽快。





plz help me asap.

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string conn = "Data Source=.;Initial Catalog=LearningSP;Integrated Security=True";
            SqlConnection con = new SqlConnection(conn);
            con.Open();
           
            SqlCommand cmd = new SqlCommand();
            
           

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@rollno",100));
            cmd.Connection = con;
            cmd.ExecuteNonQuery();
            con.Close();
            
        }
    }
}

推荐答案

cmd.CommandText = "sampleproc";


您的错误是如此清楚..,您错过了SqlCommand中的CommandText属性。

检查以下链接

这里 [ ^ ]



谢谢

-RA
Your Error is so clear.., You have missed the CommandText Property in your SqlCommand.
Check below link
Here[^]

Thanks
-RA


这篇关于ExecuteNonQuery:CommandText属性尚未初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆