473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

A vb code shows the use of datakeys

Hello All,
I need a delete and update vb codes to understand how the datakeys functions....
Thanks,
Jan 5 '07 #1
2 928
Hello All,
I need a delete and update vb codes to understand how the datakeys functions....
Thanks,
Update Example:
Expand|Select|Wrap|Line Numbers
  1. Dim key as String = Datagrid1.DataKeys(e.Item.ItemIndex)
  2.  
  3. StoryDA.SelectCommand.CommandText = "SELECT * FROM Story_Master WHERE SID=" & key
  4.         StoryDA.UpdateCommand = OleDbUpdateCommand1
  5.         Dim workParm As OleDbParameter = StoryDA.UpdateCommand.Parameters.Add(key, OleDbType.Integer)
  6.         workParm.SourceColumn = "SID"
  7.         workParm.SourceVersion = DataRowVersion.Original
  8.         StoryDA.Fill(StorySet)
  9.         Dim workrow As DataRow = StorySet.Story_Master.Rows(0)
  10.                     workrow("Story_Section") = drplistSection.SelectedItem.ToString
  11.                     Try
  12.                         StoryDA.Update(StorySet)
  13.                         Response.Redirect("Edit_Story.aspx?SID=" & Request.QueryString("SID") & "&Type=Updated")
  14.                     Catch ex As Exception
  15.                         lblErr.Text = ex.Message
  16.                     End Try
  17.  
Delete Example:
Expand|Select|Wrap|Line Numbers
  1. Dim key As String = StoryDG.DataKeys(e.Item.ItemIndex).ToString()
  2.         Dim catDA As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Story_Master WHERE SID =" & key, OleDbConnection1)
  3.         catDA.DeleteCommand = New OleDbCommand("DELETE FROM Story_Master WHERE SID = ?", OleDbConnection1)
  4.         Dim workParm As OleDbParameter = catDA.DeleteCommand.Parameters.Add(key, OleDbType.Integer)
  5.         workParm.SourceColumn = "SID"
  6.         workParm.SourceVersion = DataRowVersion.Original
  7.         Dim catDS As DataSet = New DataSet
  8.         catDA.Fill(catDS, "Story_Master")
  9. Dim cRow As DataRow = catDS.Tables("Story_Master").Rows(0)
  10.         cRow.Delete()
  11.         Dim modRows() As DataRow = catDS.Tables("Story_Master").Select(Nothing, Nothing, DataViewRowState.Deleted)
  12.         Try
  13.             catDA.Update(modRows)
  14.         Catch ex As Exception
  15.             Response.Write(ex.Message)
  16.         End Try
  17.  
Hope this helps, if you need explaining, just let me know
Jan 6 '07 #2
Thanks for the reply Jaketrible...
Jan 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Marina | last post by:
Hi, There is a component that is binding the results of a search to a DataList. By clicking on an image in the datalist, the user can download that particular item. We are using the DataKeys...
1
by: JBD | last post by:
Hi, I have a button that fires the below sub routine. This works fine if the user clicks the button as they are supposed to, even if they click it repeatedly. However, if you click "refresh" on...
0
by: Alex | last post by:
Howcan I assign the DataKeys property of the datagrid programatically from a datasource not using the property builder? E.g. Data_grid1.DataKeys = ???? a column from the dataset?
2
by: Dave | last post by:
Can anybody help me with BaseDataList.DataKeys? I always get this error: Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size...
2
by: cmay | last post by:
I am binding a List(Of T) to a DataList. In this case, T is a class Test, which has a property TestId. I am trying to use the DataKeyField with this <asp:DataList DataKeyField="TestId" ... ...
0
by: Benton | last post by:
Hi there, I have a GridView with DataKeyNames="SID" on the markup. To me surprise, I can get this value just fine in the RowDeleting and RowEditing events, for instance: string pk =...
3
by: shapper | last post by:
Hello, I need to loop though each row in a GridView and if the checkbox is a Template Field is checked I want to display the value of an invisible column named "LevelName". I tried everything...
0
by: =?Utf-8?B?cmxt?= | last post by:
I have a gridview updating every 5 seconds. There are several DataKeys declared which I access successfully in the RowDataBound event. However, in the ROwCommand event the count of the DataKeys...
12
by: dorandoran | last post by:
I followed this link to add new record from gridview. So far it's good but I need to modify the last piece to edit the record that I will supply the record id. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.