リストボックスに列を表示できるように、ローカルSQL Server Expressインスタンスへの接続を設定しようとしています。 Th buildは正常に動作し、エラーは表示されませんが、リストボックスにはデータはありません。私はクエリをテストして、それは問題ありません。私はNT認証をデータベースに使用しています。私が間違っている可能性のあるアイデア?あなたの接続文字列は奇妙なようだADO.NETによるSQL Serverへの接続 - 空のリストボックス
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void customers_SelectedIndexChanged(object sender, EventArgs e)
{
string commstring = "Driver ={SQL Server}; Server = DESKTOP-5T4MHHR\\SQLEXPRESS; Database = AdventureWorks2014; Trusted_Connection = Yes;";
string connstring = "SELECT FirstName, LastName FROM Person.Person";
SqlDataAdapter customerDataAdapater = new SqlDataAdapter(commstring, connstring);
DataSet customerDataSet = new DataSet();
customerDataAdapater.Fill(customerDataSet, "Person.Person");
DataTable customerDataTable = new DataTable();
customerDataTable = customerDataSet.Tables[0];
foreach (DataRow dataRow in customerDataTable.Rows)
{
customers.Items.Add(dataRow["FirstName"] + " (" + dataRow["LastName"] + ")");
}
}
}
データベースは** AdventureWorks2014 **ですが、** Person.Person **を使用しています。どうやって? ** AdventureWorks2014.Person **です。 – Berkay
@BerkayYaylaciテーブル名に間違いはありませんが、OPはテーブルのスキーマを指定しています。実際、 'AdventureWorks2014.Person'が間違っていると、' AdventureWorks2014.dbo.Person'と入力する必要があります。 –
@PanagiotisKanavosありがとう、良い点。 – Berkay