C#Windows应用程序用于从数据库检索数据 [英] C# windows application for retrive data from Data Base
本文介绍了C#Windows应用程序用于从数据库检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我必须从数据库表中检索数据并将其显示在文本框中,该文本框通过以下命令获取数据:
Hi All,
I have to retrieve data from DB Table and display it to the text box where getting data by below command:
SqlCommand cmd = new SqlCommand("Select * from testTable Where RollNumber= " + txtRollNumber, Con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds, "TestTable");
if (ds.Tables["TestTable"].Rows.Count > 0)
{
DataRow row;
row = ds.Tables[0].Rows.Find(id);
txtRollNumber.Text = row["RollNumber"];
txtname.Text = row["Name"];
txtAge.Text = row["Age"];
}
但显示错误,请帮助
谢谢&问候
Indrajit
but it is showing error please help
Thanks & Regards
Indrajit
推荐答案
u可以这样做
u can do like this
txtRollNumber.Text = ds.Tables[0].Rows[0]["ColumnName"].ToString();
尝试并调试源代码,以查看遇到的错误.
您可以放置断点,还可以在执行过程中查看变量的值(使用快速监视).
这甚至可以在将来帮助您解决此类问题.
Try and debug your source code to see what error you are getting.
You can put breakpoints and also look at the values of the variable during execution (using quick watch).
This will help you get to solutions to such problems even in the future.
SqlConnection con = new SqlConnection("Connection String");
SqlDataAdapter adp = new SqlDataAdapter("sqlquery", con);
DataSet ds = new DataSet();
adp.Fill(ds);
这篇关于C#Windows应用程序用于从数据库检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文