Winforms 函数未返回第二列

Winforms 函数未返回第二列,winforms,Winforms,我有一个这样的函数 public static string GetNumberOfColumns(string ConnectionString) { StringBuilder sb = new StringBuilder(); try { //Instance of SQL connection is created. using(var sConnection = new SqlConnection(ConnectionString)

我有一个这样的函数

public static string GetNumberOfColumns(string ConnectionString)
{
    StringBuilder sb = new StringBuilder();

    try
    {
       //Instance of SQL connection is created.
       using(var sConnection = new SqlConnection(ConnectionString))

       //Instance of SQL command is created.
       using(var sCommand = sConnection.CreateCommand())
       {
          //Opens the connection.
          sConnection.Open();

          //Query to get the list of tables and the number of columns they have.
          sCommand.CommandText = @"SELECT
                                                  t.table_name 
                                                 AS
                                                  TABLES,

                                                  COUNT(*)   
                                               FROM 
                                                  INFORMATION_SCHEMA.TABLES t    
                                               JOIN 
                                                  INFORMATION_SCHEMA.COLUMNS c
                                                 ON 
                                                  c.table_name = t.table_name 
                                              WHERE
                                                  t.table_name <> 'dtProperties' 
                                           GROUP BY 
                                                  t.table_name ";

          using(var reader = sCommand.ExecuteReader())
          {
              while(reader.Read())
              {
                 sb.AppendLine(reader.GetString(0));
              }
          }
      }
   }
   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 sb.ToString();
}
公共静态字符串GetNumberOfColumns(字符串连接字符串)
{
StringBuilder sb=新的StringBuilder();
尝试
{
//已创建SQL连接的实例。
使用(var sConnection=newsqlconnection(ConnectionString))
//创建SQL命令的实例。
使用(var sCommand=sConnection.CreateCommand())
{
//打开连接。
sConnection.Open();
//查询以获取表列表及其列数。
sCommand.CommandText=@“选择
t、 表名称
像
桌子,
计数(*)
从…起
信息\u SCHEMA.t表
参加
信息\u SCHEMA.c列
在…上
c、 table\u name=t.table\u name
哪里
t、 表\u名称“dtProperties”
分组
t、 表“名称”;
使用(var reader=sCommand.ExecuteReader())
{
while(reader.Read())
{
sb.AppendLine(reader.GetString(0));
}
}
}
}
捕获(例外情况除外)
{
//所有异常都被处理并写入事件日志。
事件日志=新事件日志(“应用程序”);
log.Source=“MFDBAnalyser”;
log.WriteEntry(例如Message);
}
使某人返回字符串();
}
这个函数应该返回表名及其列数,但现在它只返回表名,而不返回列数


你们能帮帮我吗…

你们还需要在数据读取器中获取第二列(它的值)

using(var reader = sCommand.ExecuteReader())
{
   while(reader.Read())
   {  
       int count = reader.GetInt(1);
       sb.AppendLine(reader.GetString(0));
   }
}
这不是自动发生的——您需要明确地从读取器中获取数据并以某种方式存储(这样您就可以返回数据)