将数据从sql转发到文本框 [英] retreve data from sql to textbox
本文介绍了将数据从sql转发到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们
我想通过c#代码(数据集)从数据库到文本框的价值。你可以帮我修改从sql到文本框的数据。
解决方案
你可以用这个来获取数据:
DataTable t = new DataTable();
使用(SqlConnection c = new SqlConnection( 在这里传递您的连接字符串))
{
c.Open();
使用(SqlDataAdapter a = new SqlDataAdapter( 在此处传递您的查询,c))
{
a.Fill(t);
}
}
您可以使用以下方法将数据附加到文本框:
textBox1.Text = t.Rows [0] [0] .ToString();
>
试试这个 -
private DataTable GetCurrentMembers( )
{
AppSQL app1 = new AppSQL(System.Configuration.ConnectionStrings [ MyconnectionString]。ConnectionString); string SqlText = @
从成员中选择计数(*)
其中activemembers = 0且pID = + _pid
DataSet ds = new DataSet();
app1.FillDataSet(ds);
return ds.Tables [ 0 ];
}
然后:
myTextBox.Text = GetCurrentMembers()。行[ 0 ] [ 0 ]。ToString();
Dear friends
I want to shwo value from database to text box through c# code(dataset). can u please help me to retreve data from sql to text box.
解决方案
You can get the data by using this:
DataTable t = new DataTable(); using (SqlConnection c = new SqlConnection("pass your connection string here")) { c.Open(); using (SqlDataAdapter a = new SqlDataAdapter("Pass your Query Here", c)) { a.Fill(t); } }
You can attach the data to the textbox by using this:
textBox1.Text=t.Rows[0][0].ToString();
Hi,
Try this-
private DataTable GetCurrentMembers() { AppSQL app1 = new AppSQL(System.Configuration.ConnectionStrings["MyconnectionString"].ConnectionString);string SqlText = @" select count(*) from member where activemembers = 0 and pID = " + _pid DataSet ds = new DataSet(); app1.FillDataSet(ds); return ds.Tables[0]; }
and then :
myTextBox.Text = GetCurrentMembers().Rows[0][0].ToString();
这篇关于将数据从sql转发到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文