Ich habe eine Funktion zum Zurückgeben der Liste der Tabellen mit Primärschlüssel in einer Datentabelle, aber jetzt ist es erforderlich, die Tabellenliste in der Zeichenfolge Rückgabetyp abrufen.Müssen den DataTable Rückgabetyp in Zeichenfolge konvertieren
Meine Methode ist wie folgt:
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;
}
Aber jetzt will ich diese Logik in der Funktion unten genannt zu werden ... Ich habe versucht, aber es ist nicht geschehen.
public class PrimaryKeyChecker : IMFDBAnalyserPlugin
{
public string RunAnalysis(string ConnectionString)
{
return "string";
}
}
Ich brauche den Rückgabetyp der Funktion String-Typ und die gesamte Logik einzustellen in der RunAnalysis Methode
würde euch bitte helfen Sie mir abgedeckt werden !!!
Wie ich die Tabelle vom Server binden und in einer Datentabelle speichern und dann in einem Datagrid befüllen – Srivastava
Bitte zeigen Sie uns, was Sie versucht haben? – TalentTuner