String^ sqlquery = "INSERT INTO Test (column1, column2, column3, column4, column5) VALUES (@param1, @param2, @param3, @param4, @param5)";
SqlCommand^ cmd = gcnew SqlCommand(sqlquery, %con);
// Добавляем параметры
cmd->Parameters->AddWithValue("@param1", textBox1->Text);
cmd->Parameters->AddWithValue("@param2", textBox2->Text);
cmd->Parameters->AddWithValue("@param3", textBox3->Text);
cmd->Parameters->AddWithValue("@param4", textBox4->Text);
cmd->Parameters->AddWithValue("@param5", textBox5->Text);
NatsuУченик (210)
3 недели назад
Скажите пожалуйста, куда в коде впихнуть?
// Добавляем параметры
cmd->Parameters->AddWithValue("@param1", textBox1->Text);
cmd->Parameters->AddWithValue("@param2", textBox2->Text);
cmd->Parameters->AddWithValue("@param3", textBox3->Text);
cmd->Parameters->AddWithValue("@param4", textBox4->Text);
cmd->Parameters->AddWithValue("@param5", textBox5->Text);
Данные вводятся здесь
Код для кнопки:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
label6->Text = text1.ToString();
if (text1 > num && textBox1->Text != "")
{
try
{
String^ connectionstring = "Data Source=WIN-DFFK8CA8HJQ\\SQLEXPRESS;Initial Catalog=DBConstructorTesting;Persist Security Info=True;Integrated Security=true;";
SqlConnection con(connectionstring);
con.Open ();
String^ sqlquery = "Insert into Test values ('"+this->textBox1->Text+"','" + this->textBox2->Text + "','" + this->textBox3->Text + "','" + this->textBox4->Text + "','" + this->textBox5->Text + "')";
SqlCommand cmd(sqlquery, % con);
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception^ ex)
{
throw ex;
}
num += 1;
label5->Text = num.ToString();
textBox1->Text = "";
textBox2->Text = "";
textBox3->Text = "";
textBox4->Text = "";
textBox5->Text = "";
}
else
{
button1->Text = "Завершить";
}
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
String^ tQuestion;
tQuestion = textBox1->Text;
}
private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
String^ tAnswer_1;
tAnswer_1 = textBox2->Text;
}
private: System::Void textBox3_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
String^ tAnswer_2;
tAnswer_2 = textBox3->Text;
}
private: System::Void textBox4_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
String^ tAnswer_3;
tAnswer_3 = textBox4->Text;
}
private: System::Void textBox5_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
String^ tAnswer_4;
tAnswer_4 = textBox5->Text;
}
Помогите пожалуйста решить проблему.