嗨我收到此错误" CommandText属性尚未初始化"
代码如下:
private DataTable GetData(string p) { DataTable dt = new DataTable(); string constr = ConfigurationManager.ConnectionStrings [" ApplicationServices"]。ConnectionString; 使用(SqlConnection con = new SqlConnection(constr)) { using(SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query)) { 使用(SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.Text; cmd.Connection = con; sda.SelectCommand = cmd; sda.Fill(dt); }¥b $ b }¥b $ b 返回dt; } b $ b}
任何人都知道帮助我解决问题。
Divya Diya
解决方案
异常消息提示您在调用Fill方法之前需要将SELECT查询分配给cmd.CommandText属性。确保查询变量的值不为空或为空。
hi am getting this error "CommandText property has not been initialized"
The code is below:
private DataTable GetData(string p) { DataTable dt = new DataTable(); string constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.Text; cmd.Connection = con; sda.SelectCommand = cmd; sda.Fill(dt); } } return dt; } }
Anyone Know help me to solve the issue.
Divya Diya
解决方案
The exception message is giving you a hint that a SELECT query needs to be assigned to the cmd.CommandText property before invoking the Fill method. Make sure the value of the query variable is not null or empty.
更多推荐
如何解决CommandText属性尚未初始化?
发布评论