difference in coding if i have an sql server instead of OleDb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dianaj86
    New Member
    • Jan 2007
    • 11

    difference in coding if i have an sql server instead of OleDb

    Hello All,
    I wanna ask, if i have an sql server....how these codes will be written..they are using OLeDb....should I just change the word OleDb with SQl?



    Update example:-

    Dim key as String = Datagrid1.DataK eys(e.Item.Item Index)

    StoryDA.SelectC ommand.CommandT ext = "SELECT * FROM Story_Master WHERE SID=" & key
    StoryDA.UpdateC ommand = OleDbUpdateComm and1
    Dim workParm As OleDbParameter = StoryDA.UpdateC ommand.Paramete rs.Add(key, OleDbType.Integ er)
    workParm.Source Column = "SID"
    workParm.Source Version = DataRowVersion. Original
    StoryDA.Fill(St orySet)
    Dim workrow As DataRow = StorySet.Story_ Master.Rows(0)
    workrow("Story_ Section") = drplistSection. SelectedItem.To String
    Try
    StoryDA.Update( StorySet)
    Response.Redire ct("Edit_Story. aspx?SID=" & Request.QuerySt ring("SID") & "&Type=Updated" )
    Catch ex As Exception
    lblErr.Text = ex.Message
    End Try


    Delete Example:
    Code:

    Dim key As String = StoryDG.DataKey s(e.Item.ItemIn dex).ToString()
    Dim catDA As OleDbDataAdapte r = New OleDbDataAdapte r("SELECT * FROM Story_Master WHERE SID =" & key, OleDbConnection 1)
    catDA.DeleteCom mand = New OleDbCommand("D ELETE FROM Story_Master WHERE SID = ?", OleDbConnection 1)
    Dim workParm As OleDbParameter = catDA.DeleteCom mand.Parameters .Add(key, OleDbType.Integ er)
    workParm.Source Column = "SID"
    workParm.Source Version = DataRowVersion. Original
    Dim catDS As DataSet = New DataSet
    catDA.Fill(catD S, "Story_Mast er")
    Dim cRow As DataRow = catDS.Tables("S tory_Master").R ows(0)
    cRow.Delete()
    Dim modRows() As DataRow = catDS.Tables("S tory_Master").S elect(Nothing, Nothing, DataViewRowStat e.Deleted)
    Try
    catDA.Update(mo dRows)
    Catch ex As Exception
    Response.Write( ex.Message)
    End Try
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    I create an SqlConnection & SqlDataAdapter, use a connection string and SqlCommand for Select etc. I would recommend rewriting the script to ensure all the references etc are correct, rather than trying to convert it..

    Hope that this helps.

    Comment

    • dianaj86
      New Member
      • Jan 2007
      • 11

      #3
      Thanks kenobewan,

      I understood what u meant, but I need 2 vb codes, using datakeys!....an d I can't find a suitable code anywhere :-S....these are the best, but I need to convert them....

      Best Regards,

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Do you mean something like:
        Code:
          strSQL &="Update publishers set Where PubID=" & D1.DataKeys(E.Item.ItemIndex)

        Comment

        • dianaj86
          New Member
          • Jan 2007
          • 11

          #5
          Well,

          I really don't know how to use datakeys!...I need two codes one to update and one to delete data from the dataGrid using datakeys...

          I`ve never used them or learnt anything about them...The teacher gave us a homework and one of the questions is how to use them...I`ve opened every website related to this topic but couldn't find any suitable code....

          That's it,

          Comment

          • kenobewan
            Recognized Expert Specialist
            • Dec 2006
            • 4871

            #6
            I knew nothing about datakeys until I saw your question. I researched, applied the principles and components I knew to sketch an outline. You may have what you need already to do what you want - if you apply the right logic and syntax. In programming knowledge is definitely secondary to logic.

            My suggestion is to have a go and post your code. Good luck :).

            Comment

            • dianaj86
              New Member
              • Jan 2007
              • 11

              #7
              Thanks kenobewan :-)

              it seems that I am gonna post it like that,

              Good Luck too,

              Comment

              Working...