【发布时间】:2016-01-25 06:32:59
【问题描述】:
我目前正在 C# Windows 窗体上制作一个投票应用程序。
所以我做了一个 SQL 查询来计算有多少人投票给了将显示在 textBox4 上的特定候选人
private void button1_Click(object sender, EventArgs e)
{
string idcan = textBox3.Text;
string score = textBox4.Text;
Connection con = new Connection();
SqlConnection sqlcon = con.Sambung();
sqlcon.Open();
string cek = "select count (ID_Candidate) as Score from DataVote where ID_Candidate = @idcan";
using (sqlcon)
{
SqlCommand com = new SqlCommand(cek, sqlcon);
com.Parameters.Add("idcan", SqlDbType.VarChar, 5).Value = score;
}
try
{
sqlcon.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
如何将上述SQL查询的结果显示到textBox4?
【问题讨论】:
标签: c# sql-server winforms visual-studio textbox