Может понравиться кому-то сказать, как я могу вставлять данные из текстового блока в базу данных SQL, но в двоичном формате. Вот часть моего кода:Вставьте двоичные данные из текстового поля в столбец
private void button1_Click(object sender, EventArgs e)
{
string connectionString = @"Data Source=" + File.ReadAllText("Server.ini") + ";" + "Initial Catalog=" + "lin2db" + ";" + "User ID=" + File.ReadAllText("User.ini") + ";" + "Password=" + File.ReadAllText("Password.ini");
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO server (id, name, ip, inner_ip, ageLimit, pk_flag, kind, port, region) VALUES (@id, @name, @ip, @inner_ip, @ageLimit, @pk_flag, @kind, @port, @region)";
command.Parameters.AddWithValue("@id", textBox1.Text);
command.Parameters.AddWithValue("@name", textBox2.Text);
command.Parameters.AddWithValue("@ip", textBox3.Text);
command.Parameters.AddWithValue("@inner_ip", textBox4.Text);
command.Parameters.AddWithValue("@ageLimit", textBox5.Text);
command.Parameters.AddWithValue("@pk_flag", textBox6.Text);
command.Parameters.AddWithValue("@kind", textBox7.Text);
command.Parameters.AddWithValue("@port", textBox8.Text);
command.Parameters.AddWithValue("@region", textBox9.Text);
connection.Open();
command.ExecuteNonQuery();
}
Вам нужно добавить более подробную информацию о том, что вы пытаетесь, и, возможно, какие ошибки вы получаете. Код, который у вас есть в вопросе, выглядит хорошо, и ничего не показывает о двоичных данных ... –
@MaxVernon Проблема в том, что я не делаю, чтобы данные из текстового поля были вставлены в таблицу sql как двоичные, exmaple здесь 'command.Parameters.AddWithValue (" @ id ", textBox1.Text);' Я хочу добавить двоичный файл –