private void button_save_insert_Click(object sender, EventArgs e)
{
try
{
customers_form.DGV_customers.DataSource = null;
conn.Open();
sql = @"select * from st_insert(:_member_id,:_name,:_phone:_number,:_address,:_height,:_weight,:_age)";
cmd = new NpgsqlCommand(sql, conn);
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
//customers_form DGV_customers = new customers_form();
customers_form.DGV_customers.DataSource = dt;
customers_form.DGV_customers.Rows.Add(textBox_member_id.Text, textBox_name.Text, textBox_phone_number.Text, textBox_address.Text, textBox_height.Text, textBox_weight.Text, textBox_age.Text);
cmd.Parameters.AddWithValue("_member_id", textBox_member_id.Text);
cmd.Parameters.AddWithValue("_name", textBox_name.Text);
cmd.Parameters.AddWithValue("_phone_number", textBox_phone_number.Text);
cmd.Parameters.AddWithValue("_address", textBox_address.Text);
cmd.Parameters.AddWithValue("_height", textBox_height.Text);
cmd.Parameters.AddWithValue("_weight", textBox_weight.Text);
cmd.Parameters.AddWithValue("_age", textBox_age.Text);
if((int)cmd.ExecuteScalar() == 1)
{
conn.Close();
//this.Close();
MessageBox.Show("Success insert a new Customers", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
button_save_insert.PerformClick();
}
}
catch(Exception ex)
{
MessageBox.Show("Error: "+ex.Message, "INSERT FAIL", MessageBoxButtons.OK, MessageBoxIcon.Error);
conn.Close();
}
}
Функция для вставки в pgadmin:
create function st_insert
(
_name character,
_phone_number character,
_address character,
_height character,
_weight character,
_age integer
)returns int as
$$
begin
insert into customers
(
name,
phone_number,
address,
height,
weight,
age
)values
(
_name,
_phone_number,
_address,
_height,
_weight,
_age
);
if found then
return 1;
else
return 0;
end if;
end
$$
language plpgsql
Показать ошибку в visual studio c#
Ошибка: 42601: синтаксическая ошибка в или около ":"