mysql parameters_MySqlCommand Command.Parameters.Add已过时
我正在Visual Studio 2010中制作一個C#Windows Form應(yīng)用程序。
該應(yīng)用程序正在連接到mysql數(shù)據(jù)庫,我想在其中插入數(shù)據(jù)。
現(xiàn)在我有這部分代碼了:
MySqlConnection connection;
string cs = @"server=server ip;userid=username;password=userpass;database=databse";
connection = new MySqlConnection(cs);
connection.Open();
MySqlCommand command = new MySqlCommand();
string SQL = "INSERT INTO `twMCUserDB` (`mc_userName`, `mc_userPass`, `tw_userName`, `tw_userPass`) VALUES ('@mcUserName', '@mcUserPass', '@twUserName', '@twUserPass')";
command.CommandText = SQL;
command.Parameters.Add("@mcUserName", mcUserNameNew);
command.Parameters.Add("@mcUserPass", mcUserPassNew);
command.Parameters.Add("@twUserName", twUserNameNew);
command.Parameters.Add("@twUserPass", twUserPassNew);
command.Connection = connection;
command.ExecuteNonQuery();
connection.Close();
連接很好。那個有效。
我在這里讀到,現(xiàn)在的方式是執(zhí)行查詢的一種保存方式。這樣還對嗎?
現(xiàn)在是真正的問題。通過上面的代碼,我在Visual Studio中收到以下警告:
'MySql.Data.MySqlClient.MySqlParameterCollection.Add(string, object)' is obsolete: '"Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value)"'
該警告適用于每個參數(shù)。
而且它甚至都不起作用,因為插入的值是@ mcUserName,@ mcUserPass等,而不是變量mcUserNameNew等所保存的值…
所以我的問題是,我做錯什么了嗎,SQL注入保存查詢的新方法是什么?
總結(jié)
以上是生活随笔為你收集整理的mysql parameters_MySqlCommand Command.Parameters.Add已过时的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue中create 什么触发_vue中
- 下一篇: mysql 多表查询练习题_mysql多