久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='CUAlV'><tr id='CUAlV'><dt id='CUAlV'><q id='CUAlV'><span id='CUAlV'><b id='CUAlV'><form id='CUAlV'><ins id='CUAlV'></ins><ul id='CUAlV'></ul><sub id='CUAlV'></sub></form><legend id='CUAlV'></legend><bdo id='CUAlV'><pre id='CUAlV'><center id='CUAlV'></center></pre></bdo></b><th id='CUAlV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='CUAlV'><tfoot id='CUAlV'></tfoot><dl id='CUAlV'><fieldset id='CUAlV'></fieldset></dl></div>

  • <tfoot id='CUAlV'></tfoot>
      • <bdo id='CUAlV'></bdo><ul id='CUAlV'></ul>

      <legend id='CUAlV'><style id='CUAlV'><dir id='CUAlV'><q id='CUAlV'></q></dir></style></legend>

      1. <small id='CUAlV'></small><noframes id='CUAlV'>

        C# 表單未將值插入 SQL Server 數(shù)據(jù)庫(kù)

        C# Form not inserting values into SQL Server database(C# 表單未將值插入 SQL Server 數(shù)據(jù)庫(kù))
      2. <small id='dX0Rs'></small><noframes id='dX0Rs'>

              • <bdo id='dX0Rs'></bdo><ul id='dX0Rs'></ul>

                  <i id='dX0Rs'><tr id='dX0Rs'><dt id='dX0Rs'><q id='dX0Rs'><span id='dX0Rs'><b id='dX0Rs'><form id='dX0Rs'><ins id='dX0Rs'></ins><ul id='dX0Rs'></ul><sub id='dX0Rs'></sub></form><legend id='dX0Rs'></legend><bdo id='dX0Rs'><pre id='dX0Rs'><center id='dX0Rs'></center></pre></bdo></b><th id='dX0Rs'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='dX0Rs'><tfoot id='dX0Rs'></tfoot><dl id='dX0Rs'><fieldset id='dX0Rs'></fieldset></dl></div>
                • <tfoot id='dX0Rs'></tfoot>
                    <tbody id='dX0Rs'></tbody>
                  <legend id='dX0Rs'><style id='dX0Rs'><dir id='dX0Rs'><q id='dX0Rs'></q></dir></style></legend>

                  本文介紹了C# 表單未將值插入 SQL Server 數(shù)據(jù)庫(kù)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我有一個(gè)簡(jiǎn)單的創(chuàng)建一個(gè)新用戶(hù)表單,它從兩個(gè)文本框中獲取值,用戶(hù)名和密碼.button2 單擊事件應(yīng)采用這些值并將它們插入到數(shù)據(jù)庫(kù)中的用戶(hù)表中.但是,當(dāng)我運(yùn)行我的代碼時(shí),會(huì)出現(xiàn)消息框說(shuō)數(shù)據(jù)已添加,我無(wú)法使用 VS2010 看到數(shù)據(jù)庫(kù)中的數(shù)據(jù).

                  I have a simple create a new user form which takes values from two text boxes, username and password. The button2 click event should take these values and insert them into the Users table in the database. However, when I run my code the message box appears to say the data has been added, I cannot see the data in the database using VS2010.

                  查看 VS 中數(shù)據(jù)庫(kù)連接的屏幕截圖.我還在 VS 中創(chuàng)建了數(shù)據(jù)庫(kù)的數(shù)據(jù)源.

                  See screen shot for the database connection in VS. I have also created a datasource of the database in VS.

                  有什么想法嗎?

                  非常感謝.

                  private void button2_Click(object sender, EventArgs e)
                      {
                          string username = txtUsername.Text;
                          string password = txtPassword.Text;
                          string sqlquery;
                          string connection = @"Data Source=.SQLEXPRESS;AttachDbFilename='C:UsersNickDocumentsVisual Studio 2010ProjectsDebenhamsProjectOffice V.01DebenhamsProjectOffice V.01DebenhamsProjectOfficeDatabase.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True";
                          SqlConnection cn = new SqlConnection(connection);
                          try
                          {
                              cn.Open();
                          }
                          catch (Exception)
                          {
                              MessageBox.Show("Unable to connect to Database");
                          }
                  
                          sqlquery = "INSERT INTO Users (Username, Password) VALUES ('" + txtUsername.Text + "','" + txtPassword.Text + "')";
                          try
                          {
                              SqlCommand command = new SqlCommand(sqlquery, cn);
                              command.Parameters.AddWithValue("Username", username);
                              command.Parameters.AddWithValue("Password", password);
                              command.Parameters.Clear();
                              MessageBox.Show("User Added");
                          }
                          catch (Exception ex)
                          {
                              MessageBox.Show(ex.Message);
                          }
                          txtUsername.Text = "";
                          txtPassword.Text = "";
                          cn.Close();
                      }
                  

                  推薦答案

                  只是嘗試修復(fù)代碼.有些元素很重要,有些元素只是優(yōu)雅.試試看,它可能會(huì)起作用.或者可以指出錯(cuò)誤所在:

                  Just trying a code fix. Some elements are crucial, some are just elegant. Try it, it might work., or could point to where the error is:

                  private void button2_Click(object sender, EventArgs e)
                      {
                          string username = txtUsername.Text;
                          string password = txtPassword.Text;
                          string sqlquery;
                  
                          //Put away the apostrophes and used twice double quotations for
                          //the full path of the database file:
                          string connection = @"Data Source=.SQLEXPRESS;AttachDbFilename=""C:UsersNickDocumentsVisual Studio 2010ProjectsDebenhamsProjectOffice V.01DebenhamsProjectOffice V.01DebenhamsProjectOfficeDatabase.mdf"";Integrated Security=True;Connect Timeout=30;User Instance=True";
                          SqlConnection cn = new SqlConnection(connection);
                  
                          /* Better to let the program fail than think it's open and moving on
                          removed try, catch*/
                          cn.Open();
                  
                  
                          //Why using your TextBoxes values if you already created strings?
                          //changed
                  
                          //you should also be careful users can't type something like "') in the      
                          //textboxes or they may cause a SQL injection
                  
                          sqlquery = "INSERT INTO Users (Username, Password) VALUES ('" + username + "','" + password + "')";
                  
                          try
                          {
                              SqlCommand command = new SqlCommand(sqlquery, cn);
                              /* unnecessary since you already built a query command.Parameters.AddWithValue("Username", username);
                              command.Parameters.AddWithValue("Password", password);
                              command.Parameters.Clear();   */
                  
                              //Missing!!
                              command.ExecuteNonQuery();
                              MessageBox.Show("User Added");
                          }
                          catch (Exception ex)
                          {
                              MessageBox.Show(ex.Message);
                          }
                  
                          //Elegance
                          txtUsername.Clear();
                          txtPassword.Clear();
                          cn.Close();
                      }
                  

                  這篇關(guān)于C# 表單未將值插入 SQL Server 數(shù)據(jù)庫(kù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  What are good algorithms for vehicle license plate detection?(車(chē)牌檢測(cè)有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運(yùn)行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時(shí)刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時(shí)突出顯示行)
                  Calling A Button OnClick from a function(從函數(shù)調(diào)用按鈕 OnClick)

                      <bdo id='qXnKF'></bdo><ul id='qXnKF'></ul>
                      <legend id='qXnKF'><style id='qXnKF'><dir id='qXnKF'><q id='qXnKF'></q></dir></style></legend>

                      • <i id='qXnKF'><tr id='qXnKF'><dt id='qXnKF'><q id='qXnKF'><span id='qXnKF'><b id='qXnKF'><form id='qXnKF'><ins id='qXnKF'></ins><ul id='qXnKF'></ul><sub id='qXnKF'></sub></form><legend id='qXnKF'></legend><bdo id='qXnKF'><pre id='qXnKF'><center id='qXnKF'></center></pre></bdo></b><th id='qXnKF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qXnKF'><tfoot id='qXnKF'></tfoot><dl id='qXnKF'><fieldset id='qXnKF'></fieldset></dl></div>
                          <tbody id='qXnKF'></tbody>

                          <small id='qXnKF'></small><noframes id='qXnKF'>

                            <tfoot id='qXnKF'></tfoot>
                          1. 主站蜘蛛池模板: 国产视频精品在线观看 | 亚洲成人高清 | 人人草天天草 | 欧美精品黄| 久久久免费少妇高潮毛片 | 91视频进入 | 国产特级毛片aaaaaa喷潮 | 国产成人一区二区三区 | 超碰成人免费 | 亚洲精品久久久久久国产精华液 | 91在线免费视频 | 毛片国产 | 欧美在线一区二区三区四区 | 精品国产一区二区国模嫣然 | 久久久久久久一区 | 99国产精品一区二区三区 | 欧美一区二区免费在线 | 欧美国产日韩精品 | 一级欧美 | 在线视频中文字幕 | 日韩一区二区三区视频在线播放 | 亚洲成人精品在线 | 欧美美女爱爱 | 黄色毛片网站在线观看 | 精品国产精品三级精品av网址 | 日本视频一区二区三区 | 一区二区三区视频在线观看 | 午夜寂寞影院列表 | 999观看免费高清www | 亚洲综合色站 | 黑人成人网 | 天天干天天操天天射 | 欧美精品久久久久久久久老牛影院 | 99pao成人国产永久免费视频 | 精品视频免费 | 欧美性高潮 | 日韩高清一区二区 | 成人毛片网 | 欧美一区二区三 | 亚洲激情自拍偷拍 | www亚洲一区 |