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

问题描述

你好

在我的项目数据中没有插入。它显示错误连接属性尚未初始化执行。如何解决这个问题?



Code1 ---保存图像

hello
In my project data was not inserting.It shows an error that "connection property has not been initialized executenonquery".How to solve this?

Code1 --- Save Image

private void btn_SaveImage_Click(object sender, EventArgs e)
       {

           try
           {
               string connectionstring = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
               Image_SqlCo = new SqlConnection(connectionstring);
               this.Image_SqlCo.Open();
               if (Image_sqlcmd.Parameters.Count == 0)
               {
                   this.Image_sqlcmd.CommandText = "INSERT INTO tbl_ImageData(IID, Name,Picture) values(@ID,@Name,@Picture)";
                   this.Image_sqlcmd.Parameters.Add("@ID", System.Data.SqlDbType.Int, 4);
                   this.Image_sqlcmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar, 50);
                   this.Image_sqlcmd.Parameters.Add("@Picture", System.Data.SqlDbType.Image);

               }
               this.Image_sqlcmd.Parameters["@ID"].Value = this.txtId.Text;
               this.Image_sqlcmd.Parameters["@Name"].Value = this.txtImagePath.Text;
               this.Image_sqlcmd.Parameters["@Picture"].Value = this.m_barrImg;

               int iResult = this.Image_sqlcmd.ExecuteNonQuery();
               MessageBox.Show(Convert.ToString(iResult));
           }
           catch (Exception ex1)
           {
               MessageBox.Show(ex1.ToString());
           }

           finally
           {
               this.Image_SqlCo.Close();
           }

       }







Code2 --- AppConfig






Code2--- AppConfig

<<blockquote class="FQ"><div class="FQA">Quote:</div>?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>

    <add name="Constr" connectionString="Server=.\SQLEXPRESS; Integrated Security=true;Initial Catalog=IMS"/>
  </connectionStrings>
</configuration</blockquote>>

推荐答案

Image_sqlcmd.Connection = Image_SqlC;

打开后。


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

09-01 20:20