如下所示SelectCommand

如下所示SelectCommand

本文介绍了当我运行时发生错误,如下所示SelectCommand.Connection属性尚未初始化.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,如下所示:

This is my code as follows:

con.Open();
string strQuery = "select Sno,Name,Age,Address" +
             " from Details";
SqlCommand cmd = new SqlCommand(strQuery);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
con.Close();
GridView1.DataSource = ds;
GridView1.DataBind();


当我运行此错误时,将发生以下错误:


When I run this an error occurs as follows:

SelectCommand.Connection property has not been initialized.


该行中发生错误.


The error occurs in this line;

adp.Fill(ds);

推荐答案

cmd.Connection=con;


这篇关于当我运行时发生错误,如下所示SelectCommand.Connection属性尚未初始化.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 03:09