public partial class Form3 : Form
{
string var;
int ID1;
private void button1_Click(object sender, EventArgs e)
{
ID1 = int.Parse(textBox1.Text);
SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\asp\Desktop\DatabasesPractice\DatabasesPractice\soccer.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand dataCommand = new SqlCommand("SELECT Name FROM team WHERE ID = @ID1", cn);
cn.Open();
var = Convert.ToString(dataCommand.ExecuteScalar());
label3.Text = var;
}
}
它給了我一個錯誤說我必須聲明標量變量@ID
,我到處搜尋,並不能得到我的特定情況下的解決方案。如何從數據庫中獲取值?必須聲明標量變量「@ ID1」
感謝您的幫助!你的解決方案工作:D