第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何根據(jù)數(shù)據(jù)庫表查詢 C# 列表

如何根據(jù)數(shù)據(jù)庫表查詢 C# 列表

C#
蝴蝶刀刀 2022-12-04 10:52:52
當(dāng)我傳遞列表的字符串版本時,我的代碼不會從測試數(shù)據(jù)庫表返回任何行,但如果我直接傳遞列表成員,它會返回行。當(dāng)我使用消息框顯示字符串 joinedSerialsList 時,它的格式似乎正確。// Create comma delimited list of serials:int currentSerial = beginning;List<string> serialsList = new List<string>();for (int i = 0; i < count; i++){     serialsList.Add(currentSerial.ToString());     currentSerial++;}string joinedSerialsList = string.Format("({0})", string.Join(", ", serialsList));OleDbConnection connection = BadgeDatabaseDB.GetConnection();string checkStatement     = "SELECT SerialNumber, OrderNumber "     + "FROM SerialNumbersMFG "     + "WHERE SerialNumber IN (@List)";OleDbCommand command = new OleDbCommand(checkStatement, connection);command.Parameters.AddWithValue("@List", joinedSerialsList);string duplicateSerials = "";try{    connection.Open();    OleDbDataReader dataReader = command.ExecuteReader();    if (dataReader.Read())    {        duplicateSerials += dataReader["OrderNumber"].ToString() + "\n";    }}catch (OleDbException ex)    {        throw ex;    }finally    {        connection.Close();    }return duplicateSerials;
查看完整描述

1 回答

?
瀟瀟雨雨

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個贊

我重寫了你的樣本,這項(xiàng)工作:


    private IEnumerable<string> getData()

    {

        // Create comma delimited list of serials:

        int currentSerial = 4452; // your constant

        var serialsList = new List<int>();

        var count = 100;


        for (int i = 0; i < count; i++)

            serialsList.Add(currentSerial++);


        var connString = getConnectionString();


        var results = new List<string>();

        string sqlSelect = $"SELECT SerialNumber, OrderNumber FROM SerialNumbersMFG WHERE SerialNumber IN ({string.Join(",", serialsList)})";


        using (var connection = new SqlConnection(connString)) // BadgeDatabaseDB.GetConnection();

        {

            using (var command = new SqlCommand(sqlSelect, connection))

            {

                connection.Open();

                var dataReader = command.ExecuteReader();


                while (dataReader.Read())

                    results.Add(dataReader["OrderNumber"].ToString());

            }

        }


        return results;

    }


查看完整回答
反對 回復(fù) 2022-12-04
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號