如果我在单独的文件中使用类,ADO.NET 如何添加参数?
班级:
class SQLconnect
{
public static void Sql(string Command_Text)
{
string connectionPath =
"Data Source=USER\\SQLEXPRESS;Initial Catalog=db;Integrated Security=SSPI;";
SqlConnection Connection = new SqlConnection(connectionPath);
Connection.Open();
SqlCommand Command = Connection.CreateCommand();
Command.CommandText = Command_Text;
Command.ExecuteNonQuery();
Connection.Close();
}
}
范围:
SQLconnect.Sql("INSERT INTO [dbo].[work] ([name],[code])VALUES(@name, @code)");
SqlParameter param = new SqlParameter();
param.ParameterName = "@name";
param.Value = nameTextBox.Text;
param.SqlDbType = SqlDbType.Text;
// Parameters.Add(param);
param = new SqlParameter();
param.ParameterName = "@code";
param.Value = codeTextBox.Text;
param.SqlDbType = SqlDbType.Text;
// Parameters.Add(param);