데이터 테이블에 기본 키가있는 테이블의 목록을 반환하는 함수가 있지만 이제는 반환 형식으로 테이블 목록을 가져와야합니다.DataTable 반환 형식을 문자열로 변환해야합니다.
public DataTable GetAllPrimaryKeyTables
(string localServer, string userName, string password, string selectedDatabase)
{
// Create the datatable
DataTable dtListOfPrimaryKeyTables = new DataTable("tableNames");
SqlConnectionStringBuilder objConnectionString = new SqlConnectionStringBuilder();
objConnectionString.DataSource = localServer; ;
objConnectionString.UserID = userName;
objConnectionString.Password = password;
objConnectionString.InitialCatalog = selectedDatabase;
// Query to select primary key tables.
string selectPrimaryKeyTables = @"SELECT
TABLE_NAME
AS
TABLES
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE
CONSTRAINT_TYPE = 'PRIMARY KEY'
ORDER BY
TABLE_NAME";
// put your SqlConnection and SqlCommand into using blocks!
using(SqlConnection sConnection = new SqlConnection(objConnectionString.ConnectionString))
using(SqlCommand sCommand = new SqlCommand(selectPrimaryKeyTables, sConnection))
{
try
{
// Create the dataadapter object
SqlDataAdapter sDataAdapter = new SqlDataAdapter(selectPrimaryKeyTables, sConnection);
// Fill the datatable - no need to open the connection, the SqlDataAdapter will do that all by itself
// (and also close it again after it is done)
sDataAdapter.Fill(dtListOfPrimaryKeyTables);
}
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);
}
}
// return the data table to the caller
return dtListOfPrimaryKeyTables;
}
를하지만 지금 내가 시도 ...이 논리는 아래의 함수를 호출 할 싶어하지만 그렇게하지 다음과 같이
내 방법입니다.
너희들이 좀 도와 주시겠습니까
public class PrimaryKeyChecker : IMFDBAnalyserPlugin
{
public string RunAnalysis(string ConnectionString)
{
return "string";
}
}
은 내가 RunAnalysis 방법에 포함되는 문자열 유형과 전체 논리 함수의 returntype의를 조정해야합니다!
마찬가지로 서버에서 테이블을 바인딩하고 데이터 테이블에 저장하고 데이터 격자에 채우는 것 같습니까? – Srivastava
시도해 보셨습니까? – TalentTuner