如何从Select语句填写文本框数据? [英] How To Fill Text Box Data From Select Statement?
本文介绍了如何从Select语句填写文本框数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SqlDataAdapter sda2 = new SqlDataAdapter("SELECT max(id)+1 FROM [TBL_CATEGORYCUSTOMERS] ", sqlcon);
DataTable dt3= new DataTable();
sda2.Fill(dt3);
我需要将这些数据插入:
I need to insert this data to:
textbox.Text;
推荐答案
你可以使用ExecuteScalar方法
you can use ExecuteScalar method
using (var cmd = new SqlCommand("SELECT max(id)+1 FROM [TBL_CATEGORYCUSTOMERS] ", sqlcon))
{
conn.Open();
textbox.Text = cmd.ExecuteScalar().ToString();
}
首先纠正..
correct first..
SELECT max(isnull(id,0))+1 FROM [TBL_CATEGORYCUSTOMERS]
你的答案是根据你的程序,最终这是一个错误的产品....
And Your answer is according to your procedure, eventually that is a wrong produce....
if(dt3.Rows.Count>0)
{
textbox.Text=dt3.rows[0][0].tostring();
}
您使用了错误的程序来选择最大Id。
对于最简单的程序,请参阅 @DamithSL 解决方案......
you are using the wrong procedure to select the max Id.
For simplest procedure see @DamithSL solution..
这篇关于如何从Select语句填写文本框数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文