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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

C# Winform SQL Server 連接字符串

C# Winform SQL Server 連接字符串

PHP
慕村9548890 2024-01-20 22:30:34
處理使用 SQL Server 的 WinForm 項(xiàng)目。目前,my 的屬性設(shè)置為 。MusicPlayerDB.mdfCopy to Output DirectoryCopy if newer運(yùn)行我的 后,我關(guān)閉了 Winform 并繼續(xù)在服務(wù)器資源管理器中檢查該表。但似乎我的表沒(méi)有更新。但是如果我去檢查和檢查,數(shù)據(jù)就在那里。InsertIntoDBBin/DebugMusicPlayerDB.mdf解決此問(wèn)題的最佳方法是什么?我看到其他評(píng)論說(shuō)使用絕對(duì)路徑(或類似的東西),但如果可能的話,我想避免這種情況。.mdf這是我的連接字符串,private const String CONNECTION_STRING = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\MusicPlayerDB.mdf;Integrated Security=True";這是我的插入代碼:private static void InsertIntoDB(List<string> userAccout) {    String sqlQuery = "INSERT INTO dbo.UserAccount (UserName, UserPassword, PasswordQuestion, PasswordHint, PasswordKey) "                      + "VALUES (@UserName, @UserPassword, @PasswordQuestion, @PasswordHint, @PasswordKey);";    using(SqlConnection connection = new SqlConnection(CONNECTION_STRING))     {        connection.Open();          //open connection        using(SqlCommand command = new SqlCommand(sqlQuery, connection))         {                 // set up command            using(SqlTransaction trans = connection.BeginTransaction())             {                try                 {                    command.Connection = connection;                    command.Transaction = trans;                    command.Parameters.AddWithValue("@UserName", userAccout[0]);                    command.Parameters.AddWithValue("@UserPassword", userAccout[1]);                    command.Parameters.AddWithValue("@PasswordQuestion", userAccout[2]);                    command.Parameters.AddWithValue("@PasswordHint", userAccout[3]);                    command.Parameters.AddWithValue("@PasswordKey", Convert.ToInt32(userAccout[4]));                    int r = command.ExecuteNonQuery();  //execute the command                    trans.Commit();                }                 catch(Exception ex)                 {                    MessageBox.Show(ex.Message);    //couldn't execute command                }            }        }    }} //end of InsertIntoDB
查看完整描述

1 回答

?
牧羊人nacy

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊

這就是它的預(yù)期工作方式。|數(shù)據(jù)目錄|在桌面應(yīng)用中,指向可執(zhí)行文件的運(yùn)行位置。這意味著在 VS 中運(yùn)行應(yīng)用時(shí)為 bin\debug 或 bin\release(工作文件夾),但在 VS 外部運(yùn)行應(yīng)用時(shí)為安裝文件夾。

這種安排允許您將空的 MDF 保留在項(xiàng)目文件夾中,而工作副本則保留在輸出文件夾中。當(dāng)需要更改數(shù)據(jù)庫(kù)架構(gòu)中的某些內(nèi)容時(shí),可以使用服務(wù)器資源管理器更改項(xiàng)目文件夾中的副本。因此,在下一個(gè) VS 會(huì)話開(kāi)始時(shí),將在輸出文件夾中復(fù)制該文件的新副本。當(dāng)您需要分發(fā)應(yīng)用時(shí),可以在項(xiàng)目文件夾中分發(fā) MDF 文件。

當(dāng)然,如果需要檢查數(shù)據(jù)庫(kù)的工作副本中發(fā)生的情況,則可以在服務(wù)器資源管理器中創(chuàng)建指向工作文件夾中的 MDF 文件的新連接。

如果您需要更多控制,則可以更改替換字符串 |數(shù)據(jù)目錄|點(diǎn)。


查看完整回答
反對(duì) 回復(fù) 2024-01-20
  • 1 回答
  • 0 關(guān)注
  • 248 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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