DataGridView insert record

DataGridView insert record

Post by Stephe » Wed, 16 Nov 2005 05:22:36


I have a datagridview that uses a sproc for it's inserts (in the table
adapter). I was wondering which event I would use to exec the sproc.
The only one that looks like it would fit the bill is the UserAddedRow
event. I use the UserDeletingRow event to validate the deletion and
execute the delete sproc, but the UserAddedRow seems to fire the second
I start editing the new row, not once the new row is created in the
datagrid.

for example, here is my delete event (the delete command only takes the
primary key arg):

private void c_request_itemDataGridView_UserDeletingRow(object
sender, DataGridViewRowCancelEventArgs e)
{
try
{
if (MessageBox.Show("Are you sure you want delete the
selected line item(s)? This action cannot be undone.",
"Delete Line Item", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) == DialogResult.No)
{
e.Cancel = true;
}
else
{
this.c_request_itemBindingSource.EndEdit();

this.c_request_itemTableAdapter.Delete(Convert.ToInt32(e.Row.Cells[0].Value.ToString()));
}
}

catch (SqlException ex)
{
MessageBox.Show(
"There is an issue with the database connection. See
your systems administrator - btnTransfer_Click.\n\nError: " +
ex.ToString(),
"An connection error has occurred",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}

catch (Exception ex)
{
MessageBox.Show(
"The was an application error. See your systems
administrator - btnTransfer_Click.\n\nError: " + ex.ToString(),
"An error has occurred", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
 
 
 

1. INSERT INTO (Multiple-record append query/Insert multiple records)

2. INSERT INTO (Multiple-record append query/Insert multiple records)

I am trying to insert multiple records in a MS Access table (Multiple-
record append query/Insert multiple records).

I am NOT using an external database.

Here is my SQL code

INSERT INTO easy_drinks (drink_name, main, amount1, second, amount2,
directions)
VALUES
('Blackthorn', 'tonic water', 1.5, 'pineapple juice', 1, 'stir with
ice, strain into *** tail glass with lemon twist'),
('Blue Moon', 'soda', 1.5, 'blueberry juice', .75, 'stir with ice,
strain into *** tail glass with lemon twist'),
('Oh My Gosh', 'peach nectar', 1, 'pineapple juice', 1, 'stir with
ice, strain into shot glass'),
('Lime Fizz', 'Sprite', 1.5, 'lime juice', .75, 'stir with ice, strain
into *** tail glass'),
('Kiss on the Lips', 'cherry juice', 2, 'apricot nectar', 7, 'serve
over ice with straw'),
('Hot Gold', 'peach nectar', 3, 'orange juice', 6, 'pour hot orange
juice in mug and add peach nectar'),
('Lone Tree', 'soda', 1.5, 'cherry juice', .75, 'stir with ice, strain
into *** tail glass'),
('Greyhound', 'soda', 1.5, 'grapefruit juice', 5, 'serve over ice,
stir well'),
('Indian Summer', 'apple juice', 2, 'hot tea', 6, 'add juice to mug
and top off with hot tea'),
('Bull Frog', 'iced tea', 1.5, 'lemonade', 5, 'serve over ice with
lime slice'),
('Soda and It', 'soda', 2, 'grape juice', 1, 'shake in *** tail glass,
no ice');

I get the error "Missing semi-colon at end of SQL statement"

What am I doing wrong?

Thanks!

PS - I am writing SQL statements in MS Access until I get SQL server
loaded on my work computer.

I've noticed MS Access is quirky regarding SQL statements!

John

3. Insert record in one table and it inserts a record in another

4. Add / Delete record from table - How to reposition selected record in datagridview???

5. Update existing record else insert record if no record exists

6. Use Insert Into to insert multiple records

7. Newbie-- sp with multiple record insert: how to get all inserted identities

8. Duplicate records are being inserted with one insert command.

9. On a SQL insert, how can I get the RRN of the record inserted?

10. After insert trigger to change inserted record values

11. Loss of inserted records during/after an insert

12. How to insert more than one record using a single insert statement

13. INSERT command fails to insert records

14. Insert records and then return ID to insert into sub table

15. Using ID from an Inserted record in a second insert