Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sqlquery = "INSERT INTO menuitems (Title, Subtitle, Subtitle_2, Dish, Price, BarName) VALUES (@Title, @Subtitle, @Subtitle_2, @Dish, @Price, @BarName)";
- npgSqlCommand = new NpgsqlCommand(sqlquery, npgSqlConnection);
- npgSqlCommand.Parameters.Add("Title", NpgsqlTypes.NpgsqlDbType.Char);
- npgSqlCommand.Parameters.Add("Subtitle", NpgsqlTypes.NpgsqlDbType.Char);
- npgSqlCommand.Parameters.Add("Subtitle_2", NpgsqlTypes.NpgsqlDbType.Char);
- npgSqlCommand.Parameters.Add("Dish", NpgsqlTypes.NpgsqlDbType.Varchar);
- npgSqlCommand.Parameters.Add("Price", NpgsqlTypes.NpgsqlDbType.Integer);
- npgSqlCommand.Parameters.Add("BarName", NpgsqlTypes.NpgsqlDbType.Text);
- foreach (var item in menu)
- {
- if (item.Title == null)
- npgSqlCommand.Parameters["Title"].Value = DBNull.Value;
- else
- npgSqlCommand.Parameters["Title"].Value = item.Title;
- if(item.Subtitle==null)
- npgSqlCommand.Parameters["Subtitle"].Value = DBNull.Value;
- else
- npgSqlCommand.Parameters["Subtitle"].Value = item.Subtitle;
- if(item.Subtitle_2==null)
- npgSqlCommand.Parameters["Subtitle_2"].Value = DBNull.Value;
- else
- npgSqlCommand.Parameters["Subtitle_2"].Value = item.Subtitle_2;
- npgSqlCommand.Parameters["Dish"].Value = item.Dish;
- npgSqlCommand.Parameters["Price"].Value = item.Price;
- npgSqlCommand.Parameters["BarName"].Value = item.BarName;
- npgSqlCommand.ExecuteNonQuery();
- }
Advertisement
Add Comment
Please, Sign In to add comment