我已經創建了一個將約束所有與主鍵的表在下拉這樣方法是故障
public void PrimaryKeyTable()
{
SqlConnection sConnection = new SqlConnection("Server=192.168.10.3;DataBase=GoalPlanNew;User Id=gp;Password=gp");
//To Open the connection.
sConnection.Open();
string selectPrimaryKeys = @"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'PRIMARY KEY'
ORDER BY TABLE_NAME";
SqlCommand sCommand = new SqlCommand(selectPrimaryKeys, sConnection);
try
{
DataSet dsListOfPrimaryKeys = new DataSet("INFORMATION_SCHEMA.TABLE_CONSTRAINTS");
SqlDataAdapter dass = new SqlDataAdapter(selectPrimaryKeys, sConnection);
dass.TableMappings.Add("Table", "INFORMATION_SCHEMA.TABLE_CONSTRAINTS");
dass.Fill(dsListOfPrimaryKeys);
DataViewManager dsvaa = dsListOfPrimaryKeys.DefaultViewManager;
cmbResults.DataSource = dsListOfPrimaryKeys.Tables["INFORMATION_SCHEMA.TABLE_CONSTRAINTS"];
cmbResults.DisplayMember = "NAME";
cmbResults.ValueMember = ("");
}
catch (Exception ex)
{
//All the exceptions are handled and written in the EventLog.
EventLog log = new EventLog("Application");
log.Source = "MFDBAnalyser";
log.WriteEntry(ex.Message);
}
finally
{
if (sConnection.State != ConnectionState.Closed)
{
sConnection.Close();
}
}
}
但不是結合與主鍵是讓這樣的事情在該表的方法dropdown
System.Data.DataRowView
System.Data.DataRowView...and so on
你能指出我出錯的地方嗎?
`cmbResults.DisplayMember =「NAME」;`列名是`「NAME」` – FosterZ 2010-11-23 11:44:59