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

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:152日期: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('請輸入用戶名和密碼進(jìn)行注冊');}else{ connection.Open();//連接到數(shù)據(jù)庫 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('用戶名重復(fù),請重新輸入');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里面的單引號應(yīng)該改為雙引號才是你的本意,但改了后需加上必要的包裹單引號。

回答2:

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

回答3:

sql拼接錯了

相關(guān)文章:
主站蜘蛛池模板: 东阳市| 新余市| 攀枝花市| 垫江县| 沙河市| 日土县| 庐江县| 南郑县| 新沂市| 和田市| 新巴尔虎右旗| 东阿县| 广宗县| 黑山县| 合阳县| 兴和县| 鄢陵县| 徐汇区| 裕民县| 丹寨县| 遂平县| 阿荣旗| 江达县| 桓仁| 乌鲁木齐县| 常山县| 彭州市| 枣阳市| 文安县| 嘉定区| 阳山县| 石景山区| 贵港市| 浙江省| 芜湖县| 固安县| 吉木萨尔县| 贡嘎县| 澄江县| 墨玉县| 宜阳县|