-1
次のコードを実行すると、nullがデータベースに格納されず、代わりに空の文字列が取得されます。その周りに道があるのですか?stringBuilderを使用してmysql C#にnullを挿入します。
string ConnectionString = "server=localhost; password = [email protected]; user = root; database=DB ";
StringBuilder sCommand = new StringBuilder("INSERT INTO mytable (Name) VALUES ");
string A = null;
using (MySqlConnection mConnection = new MySqlConnection(ConnectionString))
{
List<string> Rows = new List<string>();
for (int i = 0; i < 100000; i++)
{
Rows.Add(string.Format("('{0}')", A));
}
sCommand.Append(string.Join(",", Rows));
sCommand.Append(";");
mConnection.Open();
using (MySqlCommand myCmd = new MySqlCommand(sCommand.ToString(), mConnection))
{
myCmd.CommandType = CommandType.Text;
myCmd.ExecuteNonQuery();
}
}
パラメータ化されたクエリを使用してください。あなたはSQLインジェクション攻撃を求めています! –
mysqlライブラリがサポートしている場合は、一括挿入操作の使用を検討することもできます。 –
あなたの文字列ビルダーは何も生産的なことをしていません。 –