多部分标识符“System.Data.Datarowview”无法绑定。我收到错误请帮助我 [英] The Multi-Part Identifier "System.Data.Datarowview" Could Not Be Bound. I am Getting Error Please Help Me
本文介绍了多部分标识符“System.Data.Datarowview”无法绑定。我收到错误请帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace country_state_city
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(**************);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from Country", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
comboBox1.DataSource = ds.Tables[0];
comboBox1.SelectedIndex = -1;
comboBox1.DisplayMember = "County";
comboBox1.ValueMember = "Countryid";
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex >=0)
{
MessageBox.Show(comboBox1.SelectedIndex.ToString());
SqlDataAdapter da = new SqlDataAdapter("Select * From CountryState Where CountryId='" + comboBox1.SelectedValue + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
comboBox2.DataSource = ds.Tables[0];
comboBox2.DisplayMember = "State";
comboBox2.ValueMember = "StateId";
}
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedIndex > 0)
{
SqlDataAdapter da = new SqlDataAdapter("Select * From StateCity Where StateId='" + comboBox2.SelectedValue + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
comboBox3.DataSource = ds.Tables[0];
comboBox3.DisplayMember = "City";
comboBox3.ValueMember = "CityId";
}
}
}
}
推荐答案
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndexChanged -= comboBox1_SelectedIndexChanged;
SqlCommand cmd = new SqlCommand("select * from Country", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
comboBox1.DataSource = ds.Tables[0];
comboBox1.SelectedIndex = -1;
comboBox1.DisplayMember = "County";
comboBox1.ValueMember = "Countryid";
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
}
这篇关于多部分标识符“System.Data.Datarowview”无法绑定。我收到错误请帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文