dataadapter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

It was suggested that I post this item here. Sorry about the cross post

I am using a datagrid to display information from a table. I have successfully been able to select items and make the values appear in different textboxes on the form. I would like to be able to select a value and the click a command button and delete the corresponding record. When I load the data in the datagrid I do the following
Me.SqlDataAdapter1.SelectCommand.CommandText = "SELECT keyword,description,ID,area FROM Keywords WHERE area = '" & SelArea & "' ORDER BY Keyword
Me.SqlDataAdapter1.Fill(Me.DataSet11

I would like to know how to delete the corresponding record. I would like to do something like the following, but it seems that the dataadapter looks for insert,delete, and update commands.
Me.SqlDataAdapter1.DeleteCommand.CommandText = "delete * from keywords where id=" & Trim(DataGrid1.Item(DataGrid1.CurrentCell.RowNumber.ToString, 2)) &
" and area='" & SelArea & "'
Me.SqlDataAdapter1.Update(something goes here, but i don't know what

How should I be doing this

Thank
 
Mike,

little bit wrong things you are doing here.

you can use sqlclient.sqlparameter in your selectcommand and deletecommand.
look somewhere in the books or sample over internet. how to go for it. it's
easy. you need to make your selectcommand as

select keyword,..... from keywords where area = @area order by keyword

and deletecommand should be

delete from keywords where id = @id

just you need to set @area parameter through code. everything else will be
taken care automatically.

so, understand the concepts of parameter and your work will be more easier
and fun.

Regards,

Rajesh Patel


mike said:
It was suggested that I post this item here. Sorry about the cross post.

I am using a datagrid to display information from a table. I have
successfully been able to select items and make the values appear in
different textboxes on the form. I would like to be able to select a value
and the click a command button and delete the corresponding record. When I
load the data in the datagrid I do the following:
Me.SqlDataAdapter1.SelectCommand.CommandText = "SELECT
keyword,description,ID,area FROM Keywords WHERE area = '" & SelArea & "'
ORDER BY Keyword"
Me.SqlDataAdapter1.Fill(Me.DataSet11)

I would like to know how to delete the corresponding record. I would like
to do something like the following, but it seems that the dataadapter looks
for insert,delete, and update commands.
Me.SqlDataAdapter1.DeleteCommand.CommandText = "delete * from keywords
where id=" & Trim(DataGrid1.Item(DataGrid1.CurrentCell.RowNumber.ToString,
2)) & _
 
Back
Top