我有与combobox控件连接的DatagridView。组合框用于过滤来自表格的数据。 Datagridview中的组合框和数据来自同一个表。我寻找错误,但找不到。它说: 不正确的语法靠近System.Data.DataRowVievSystem.Data.DataRowViev附近的语法不正确
我点击确定按钮,然后其他错误: 连接未关闭。连接的当前状态是打开的。 请帮助
private void VraboteniPoOpstini_Load(object sender, EventArgs e)
{
try
{
con.Open();
ad = new System.Data.SqlClient.SqlDataAdapter("Select * from tbl_PersonalniPodatoci ", con);
ds = new DataSet();
ad.Fill(ds, "tbl_PersonalniPodatoci");
dt = ds.Tables["tbl_PersonalniPodatoci"];
con.Close();
//fill combobox
cbOpstini.DataSource = dt;
cbOpstini.DisplayMember = "Opstina";
cbOpstini.ValueMember = "Sifra";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ГРЕШКА", MessageBoxButtons.OK);
}
}
private void cbOpstini_SelectedIndexChanged(object sender, EventArgs e)
{
string izberiOpstina = cbOpstini.SelectedValue.ToString();
string sSql;
try
{
con.Open();
//datagridview
sSql = "Select Sifra, Prezime, Ime, Opstina From tbl_PersonalniPodatoci Where Opstina'" + izberiOpstina + "' Order by Sifra";
ad = new System.Data.SqlClient.SqlDataAdapter(sSql, con);
SqlCommandBuilder cb = new SqlCommandBuilder(ad);
DataTable dt = new DataTable();
ad.Fill(dt);
con.Close();
// fill datagridview
grdOpstini.DataSource= dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ГРЕШКА", MessageBoxButtons.OK);
}
}
“不正确的语法”是的,你的代码在哪里? – BoltClock 2011-05-15 07:23:51
请仅发布相关代码! – 2011-05-15 07:43:26