当前位置: 首页>>代码示例>>C#>>正文


C# SqlCommand.GetString方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlCommand.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.GetString方法的具体用法?C# SqlCommand.GetString怎么用?C# SqlCommand.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlCommand的用法示例。


在下文中一共展示了SqlCommand.GetString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNodeMatches

        private List<string> GetNodeMatches(string lookupText)
        {
            List<string> foundNodes = new List<string>();

            string sConn = ConfigurationManager.ConnectionStrings["EEREDB"].ToString();
            sConn += System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(ConfigurationManager.AppSettings["word"].ToString()));

            using (SqlConnection conn = new SqlConnection(sConn))
            {
                conn.Open();
                using (SqlDataReader reader = new SqlCommand("SELECT DrupalNode FROM dbo.NodeLookup WHERE WebURL LIKE '%" + lookupText + "%' ", conn).ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            foundNodes.Add(reader.GetString(0));
                        }
                    }
                }
                conn.Close();
            }

            return foundNodes;
        }
开发者ID:EEREweb,项目名称:CMS-MigrationUtility,代码行数:25,代码来源:DBLookup.cs

示例2: PopulateVersionAndTypes

 protected override void PopulateVersionAndTypes()
 {
     base._sqlVersion = "10";
     List<KeyValuePair<int, byte>> list = new List<KeyValuePair<int, byte>>();
     using (SqlDataReader reader = new SqlCommand("select system_type_id, user_type_id, name from sys.types where system_type_id = user_type_id", base._cx).ExecuteReader())
     {
         while (reader.Read())
         {
             DbTypeInfo dbTypeInfo = SqlSchemaReader.GetDbTypeInfo(reader.GetString(2));
             if (!((dbTypeInfo == null) || base._sqlTypes.ContainsKey(reader.GetInt32(1))))
             {
                 base._sqlTypes.Add(reader.GetInt32(1), dbTypeInfo);
             }
             else
             {
                 list.Add(new KeyValuePair<int, byte>(reader.GetInt32(1), reader.GetByte(0)));
             }
         }
     }
     foreach (KeyValuePair<int, byte> pair in list)
     {
         if (base._sqlTypes.ContainsKey(pair.Value))
         {
             base._sqlTypes[pair.Key] = base._sqlTypes[pair.Value];
         }
     }
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:27,代码来源:AzureSchemaReader.cs

示例3: GetEnabledTables

 private static string[] GetEnabledTables(string connectionString)
 {
     SqlDataReader reader = null;
     SqlConnection connection = null;
     ArrayList list = new ArrayList();
     try
     {
         connection = new SqlConnection(connectionString);
         connection.Open();
         reader = new SqlCommand("dbo.AspNet_SqlCacheQueryRegisteredTablesStoredProcedure", connection) { CommandType = CommandType.StoredProcedure }.ExecuteReader();
         while (reader.Read())
         {
             list.Add(reader.GetString(0));
         }
     }
     catch (Exception exception)
     {
         SqlException exception2 = exception as SqlException;
         if ((exception2 != null) && (exception2.Number == 0xafc))
         {
             throw new DatabaseNotEnabledForNotificationException(System.Web.SR.GetString("Database_not_enabled_for_notification", new object[] { connection.Database }));
         }
         throw new HttpException(System.Web.SR.GetString("Cant_get_enabled_tables_sql_cache_dep"), exception);
     }
     finally
     {
         try
         {
             if (reader != null)
             {
                 reader.Close();
             }
             if (connection != null)
             {
                 connection.Close();
             }
         }
         catch
         {
         }
     }
     return (string[]) list.ToArray(Type.GetType("System.String"));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:43,代码来源:SqlCacheDependencyAdmin.cs

示例4: GetUser

        public long GetUser(string email, string hash)
        {
            long _result = -1;

            if (Connected)
            {
                using (SqlDataReader _reader = new SqlCommand(string.Format("Select * from MarketUser Where Email='{0}'", email), _sql).ExecuteReader())
                {
                    if (_reader.HasRows)
                    {
                        while (_reader.Read())
                        {
                            if (_reader.GetString(_reader.GetOrdinal("Password")).Equals(hash))
                            {
                                _result = _reader.GetInt64(_reader.GetOrdinal("UserId"));
                            }
                        }
                    }
                }
            }

            return _result;
        }
开发者ID:Afonichev,项目名称:Jobmarket,代码行数:23,代码来源:Sql.cs

示例5: TearDownDatabase

        public void TearDownDatabase()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["TeleConsult"].ConnectionString;
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (var reader = new SqlCommand("select [Name] from sys.tables WHERE TYPE='U' AND [Name] != '__MigrationHistory'", connection).ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (reader.Read())
                    {
                        var tableName = reader.GetString(0);
                        using (var connection2 = new SqlConnection(connectionString))
                        {
                            connection2.Open();
                            new SqlCommand(string.Format("DELETE FROM [{0}]", tableName), connection2).ExecuteNonQuery();
                            connection2.Close();
                        }

                    }
                }
                connection.Close();
            }
        }
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:23,代码来源:IntegrationTestService.cs

示例6: GetData

 /// <summary>
 /// Get tag ID data from the SQL database table.
 /// </summary>
 public void GetData(ListView listview)
 {
     using (sqlConn = new SqlConnection(connectionString))
     {
         sqlConn.Open();
         using (SqlDataReader reader = new SqlCommand("SELECT * FROM TagInfo", sqlConn).ExecuteReader())
         {
             try
             {
                 while (reader.Read())
                 {
                     string[] rowitem = new string[2];
                     rowitem[0] = reader.GetString(reader.GetOrdinal("TagId"));
                     rowitem[1] = reader.GetDateTime(reader.GetOrdinal("TagTime")).ToString();
                     ListViewItem listitem = new ListViewItem(rowitem);
                     //table.Rows.Add(epc, time);
                     listview.Items.Add(listitem);
                 }
                 reader.Close();
             }
             catch (System.Data.SqlClient.SqlException ee)
             {
                 MessageBox.Show(ee.Message.ToString());
             }
         }
         sqlConn.Close();
     }
 }
开发者ID:vigineshs,项目名称:A-Smart-Data-Analyzer-for-Library-Management-System,代码行数:31,代码来源:SQLMethod.cs

示例7: IsToken

        public bool IsToken(long id, string AccessToken)
        {
            bool _result = false;

            if (Connected)
            {
                using (SqlDataReader _reader = new SqlCommand(string.Format("Select * From MarketToken Where UserId='{0}'", id), _sql).ExecuteReader())
                {
                    if (_reader.HasRows)
                    {
                        while (_reader.Read())
                        {
                            if (_reader.GetString(_reader.GetOrdinal("AccessToken")).Equals(AccessToken))
                            {
                                _result = true;

                                break;
                            }
                        }
                    }

                }
            }

            return _result;
        }
开发者ID:Afonichev,项目名称:Jobmarket,代码行数:26,代码来源:Sql.cs

示例8: readFromDataBase

        public void readFromDataBase()
        {
            items.Clear();
            SqlDataReader reader = new SqlCommand(string.Format("SELECT * FROM Items ORDER BY Id;SELECT * FROM Jobs ORDER BY Item;SELECT * FROM Jobs ORDER BY Item;"), cn).ExecuteReader();
            //читаем лист items
            while (reader.Read())
            {
                item newItem = new item();
                newItem.id = reader.GetInt32(0);
                newItem.firstName = reader.GetString(1);
                newItem.lastName = reader.GetString(2);
                items.Add(newItem);
            }

            int i;
            int lastid;

            //читаем лист jobs
            reader.NextResult();
            lastid = i = -1;
            while (reader.Read())
            {
                int k = reader.GetInt32(4);
                if (lastid != k)
                {
                    do ++i;
                    while (k != items[i].id);
                    lastid = reader.GetInt32(4);
                }
                items[i].jobs.Add(new job(reader.GetDateTime(0), reader.GetString(1), reader.GetString(2), reader.GetString(3)));
            }

            //читаем лист positions
            reader.NextResult();
            lastid = i = -1;
            while (reader.Read())
            {
                if (lastid != reader.GetInt32(4))
                {
                    do i++;
                    while (reader.GetInt32(4) != items[i].id);
                    lastid = reader.GetInt32(4);
                }
                items[i].positions.Add(new position(reader.GetInt64(0),reader.GetInt64(1),reader.GetInt32(2),reader.GetDateTime(3)));
            }
            reader.Close();
        }
开发者ID:ASIXz,项目名称:SecondTask,代码行数:47,代码来源:Program.cs

示例9: Main

        public static void Main(string[] args)
        {

            //Console.WriteLine(response);

            try
            {
                while (true)
                {
                    using (var sql = new SqlConnection(Secrets.ConnectionString))
                    {
                        sql.Open();
                        // dbo.StravaKeys contains registered API keys; let's collect all of them

                        #region strava

                        var api_base = "https://www.strava.com/api/v3/";
                        var keysQuery = "SELECT * from dbo.StravaKeys;";
                        Log.Debug(keysQuery);
                        var results = new List<Tuple<int, string>>();
                        using (var keysResults = new SqlCommand(keysQuery, sql).ExecuteReader())
                        {
                            while (keysResults.Read())
                            {
                                results.Add(new Tuple<int, string>(keysResults.GetInt32(0), keysResults.GetString(1)));
                            }
                        }

                        Log.Info("Got {0} keys to check", results.Count);

                        // get updated results for each StravaKey and stick them in the DB.
                        foreach (var res in results)
                        {
                            var accessToken = $"&access_token={res.Item2}";
                            var epoch = 1451624400; // jan 1 2016
                            long secondsSinceEpoch;

                            // select the last time we updated this user; if we've never updated them, get events since January 1, 2016
                            var lastRunQuery =
                                $"SELECT activity_time FROM dbo.StravaActivities WHERE strava_id={res.Item1} ORDER BY activity_time DESC;";
                            Log.Debug(lastRunQuery);
                            using (var lastRun = new SqlCommand(lastRunQuery, sql).ExecuteReader())
                            {
                                if (lastRun.HasRows)
                                {
                                    lastRun.Read();
                                    secondsSinceEpoch =
                                        (long)
                                            Math.Max(epoch,
                                                lastRun.GetDateTime(0).Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                                }
                                else
                                {
                                    secondsSinceEpoch = epoch;
                                }
                            }

                            // transform our DB results into <DateTime, double, string> tuples
                            var apiUrl =
                                $"{api_base}athlete/activities/?per_page=200&after={secondsSinceEpoch}{accessToken}";
                            Log.Info("Hitting API at {0}", apiUrl);
                            var runs = GetArrayFromApi(apiUrl)
                                .Select(e =>
                                    new Tuple<DateTime, double, string>(
                                        DateTime.Parse((string)e["start_date"]),
                                        (double)e["distance"] / 1609, // translate meters to miles
                                        (string)e["type"]))
                                .ToList();

                            // if we actually got any tuples, transform them into an INSERT query
                            Log.Info("Got {0} results from Strava API", runs.Count);
                            if (runs.Any())
                            {
                                // aggregate the tuples into a StringBuilder
                                var insertionQuery = runs.Aggregate(
                                    new StringBuilder(
                                        "INSERT INTO dbo.StravaActivities (strava_id, activity_time, activity_distance, activity_type) VALUES "),
                                    (acc, e) => acc.Append($"({res.Item1}, '{e.Item1}', {e.Item2}, '{e.Item3}'), "));
                                // trim the last ", " from the aggregated tuples and append a semicolon
                                insertionQuery.Remove(insertionQuery.Length - 2, 2).Append(";");
                                // insert! 
                                Log.Debug(insertionQuery);
                                using (var inserter = new SqlCommand(insertionQuery.ToString(), sql))
                                    inserter.ExecuteNonQuery();
                            }
                        }

                        #endregion

                        #region withings

                        Log.Info("Hitting Withings API");
                        var lastMeasure = new DateTime(2016, 1, 1);
                        var unixTimeStart = new DateTime(1970, 1, 1);

                        var lastEntryQuery = "SELECT measure_date FROM dbo.bodyFat ORDER BY measure_date DESC;";
                        using (var lastEntry = new SqlCommand(lastEntryQuery, sql).ExecuteReader())
                        {
                            if (lastEntry.Read())
                            {
//.........这里部分代码省略.........
开发者ID:akindle,项目名称:resolutionScraper,代码行数:101,代码来源:Program.cs

示例10: cbOrder_SelectedIndexChanged

 private void cbOrder_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (SqlConnection connection = new SqlConnection(MainForm.STRCONN))
     {
         connection.Open();
         OrderBy orderBy = (OrderBy)cbOrderBy.SelectedItem;
         string q = String.Format("SELECT Country,League,Season{0} FROM dbo.Leagues ORDER BY {1} {2}",
             orderBy.SelectCol == "" ? "" : "," + orderBy.SelectCol, orderBy.OrderCol, cbOrderDir.SelectedItem);
         LeaguesKey lKey;
         lbLeagues.Items.Clear();
         using (SqlDataReader reader = new SqlCommand(q, connection).ExecuteReader())
         {
             while (reader.Read())
             {
                 lKey = new LeaguesKey();
                 lKey.Country = reader.GetString(0);
                 lKey.League = reader.GetString(1);
                 lKey.Season = reader.GetString(2);
                 if (reader.FieldCount >= 4) lKey.ExtraCol = reader.GetValue(3);
                 lbLeagues.Items.Add(lKey);
             }
         }
     }
 }
开发者ID:TheHalcyonSavant,项目名称:SoccerBase,代码行数:24,代码来源:MethodAForm.cs

示例11: button11_Click

        private void button11_Click(object sender, EventArgs e)
        {
            try
            {
                string netFileName = VissimSingleton.Instance.GetInputFileName();
                string workingDir = VissimSingleton.Instance.GetWorkingDirectory();
                string exeDir = VissimSingleton.Instance.GetExecutionDirectory();

                if (workingDir == exeDir) throw new Exception("ex");

                var files = Directory.GetFiles(workingDir, "*.*", SearchOption.TopDirectoryOnly);
                foreach (string fileName in files)
                {
                    File.Delete(fileName);
                }

                var sb = new SqlConnectionStringBuilder();
                sb.DataSource = "TOSHIBA";
                sb.InitialCatalog = "VISSIM";
                sb.IntegratedSecurity = true;

                using (var conn = new SqlConnection(sb.ConnectionString))
                {
                    conn.Open();
                    using (var reader = new SqlCommand("SELECT * FROM Files;", conn).ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                using (var fs = new FileStream(workingDir + reader.GetString(1), FileMode.Create, FileAccess.Write))
                                {
                                    var bytes = reader.GetSqlBytes(3);
                                    fs.Write(bytes.Buffer, 0, (int)bytes.Length);
                                }
                            }
                        }
                    }
                }
                
                VissimSingleton.Instance.LoadNet(workingDir + netFileName);
                VissimSingleton.Instance.LoadLayout(workingDir + "vissim.ini");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:A-n-d-r-e-y,项目名称:VISLAB,代码行数:48,代码来源:TestForm.cs


注:本文中的System.Data.SqlClient.SqlCommand.GetString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。