在我的场景中,我想插入具有15列数据的sql语句。是否有其他方法来处理插入语句的参数?
public bool GetCustomersList(ref DataSet dataset, String x, String y, string z, string x1, string y1, string z1 )
{
MySqlConnection SQLConn = GetConnection();
try
{
string get_records;
if (SQLConn.State == ConnectionState.Closed)
{
SQLConn.Open();
}
if (searchtype == "x")
{
get_records = "INSERT into table values(x, y,z,x1,y1,z1);
}
MySqlCommand command = new MySqlCommand(get_records, SQLConn);
MySqlDataAdapter mySqlAdapter = new MySqlDataAdapter(command);
mySqlAdapter.Fill(dataset);
if (SQLConn.State == ConnectionState.Open)
{
SQLConn.Close();
}
return true;
}
catch (Exception )
{
if (SQLConn.State == ConnectionState.Open)
{
SQLConn.Close();
}
return false;
}
}
这里的参数可能会扩展到15个或者更多?在asp.net中如何处理这种情况?
最佳答案
我建议你使用:
command.Parameters.Add( ... );
关于C#:如何在 MySQL 的 Insert 语句中动态插入多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13232127/