请有人告诉我如何将来自文本机器人的数据以二进制格式插入 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();
}