国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

mysql - C#連接數據庫時一直這一句出問題int i = cmd.ExecuteNonQuery();

瀏覽:132日期:2022-06-13 10:47:44

問題描述

private void button1_Click(object sender, EventArgs e)

{string MyConnectionString = 'server=localhost;user=root;database=yangbo;port=3306;password=yangbo6510;';MySqlConnection connection = new MySqlConnection(MyConnectionString);if (textBox_username.Text.Trim() == '' && textBox_password.Text.Trim() == ''){ MessageBox.Show('請輸入用戶名和密碼進行注冊');}else{ connection.Open();//連接到數據庫 string sql = 'select * from usernp where username=’' + textBox_username.Text.Trim() + '’ ;'; MySqlCommand cmd = new MySqlCommand(sql, connection); cmd.CommandType = CommandType.Text; MySqlDataReader sdr; sdr = cmd.ExecuteReader(); if (sdr.Read()) {MessageBox.Show('用戶名重復,請重新輸入');textBox_username.Clear();textBox_password.Clear(); } else {string sql1 = 'insert into usernp (username,userpassword) values(’ + textBox_username.Text.Trim() + ’,’ + textBox_password.Text.Trim() +’)';cmd = new MySqlCommand(sql1, connection);int i = cmd.ExecuteNonQuery();if (i> 0){ MessageBox.Show('注冊成功'); textBox_username.Clear(); textBox_password.Clear();}else{ MessageBox.Show('注冊不成功'); textBox_username.Clear(); textBox_password.Clear();} } connection.Close();} }

問題解答

回答1:

你倒是說一下具體出什么問題啊,另外看起來sql1里面的單引號應該改為雙引號才是你的本意,但改了后需加上必要的包裹單引號。

回答2:

首先 請不要拼接sql,其次用sqlparameter

回答3:

sql拼接錯了

相關文章:
主站蜘蛛池模板: 勐海县| 蒙城县| 错那县| 榆社县| 无为县| 中西区| 潼南县| 高陵县| 阿克| 通化县| 木兰县| 桦甸市| 玛多县| 黎平县| 新昌县| 桦甸市| 镇雄县| 龙海市| 新建县| 巴东县| 开阳县| 宁夏| 淮滨县| 定襄县| 泽普县| 巨野县| 营山县| 察隅县| 自治县| 大同市| 富锦市| 东光县| 昌江| 乐至县| 晋江市| 中宁县| 璧山县| 泊头市| 秦皇岛市| 景泰县| 青阳县|