如何将结果检索到文本框 [英] how can retrieve result to textbox

查看:88
本文介绍了如何将结果检索到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DataTable dt2 = new DataTable();
            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {
                string sqlstr2 = "select max(catId) from tblcatProducts";
                using (SqlDataAdapter dr2 = new SqlDataAdapter(sqlstr2, CS))
                {
                    SqlCommand cmd = new SqlComman();
                    textbox.tex=cmd.ExecuteReader;
                }
            }

推荐答案

cmd.ExecuteReader()返回DataReader,而不是直接返回查询结果。在该DataReader上,您必须为结果集的每一行调用.Read()。返回true / false会告诉您是否确实存在下一个结果行。然后使用其indexer []读取该行的列的值,它将为您提供列值作为对象(可能是盒装)或使用其类型专用.GetXXX-方法,如.GetInt32(int columnOrdinal )。您可以在此处找到示例: https://msdn.microsoft.com /en-us/library/haa3afyz%28v=vs.110%29.aspx [ ^ ]
cmd.ExecuteReader() returns a DataReader, not directly the query result. On that DataReader you have to call .Read() for each row of the resultset. The return of true/false tells you if there actually is a next result row. And then read the value of the column(s) of that row either with its indexer[], which will give you the column values as objects (potentially boxed) or with its type-dedicated .GetXXX-Methods like .GetInt32(int columnOrdinal). You can find an example here: https://msdn.microsoft.com/en-us/library/haa3afyz%28v=vs.110%29.aspx[^]


这篇关于如何将结果检索到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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