Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem With Get More Table Instead of one Table

Problem With Get More Table Instead of one Table

Scheduled Pinned Locked Moved Visual Basic
helpannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saba02
    wrote on last edited by
    #1

    Hi all, I have one web methode in my web service,that can only get one table from my application and it is without Transaction,

    <WebMethod()> _
    Public Function OprationONTbl(ByRef ds As Data.DataSet, ByVal TblName As String, ByVal Insert As Boolean, ByVal Update As Boolean, ByVal StrWhere As String, ByVal retValue As Boolean, ByRef StrRetValue As String) As String
    Dim cn As New SqlConnection
    Dim cmd As New SqlCommand
    Dim da As New SqlDataAdapter
    Dim cBuilder As New SqlCommandBuilder(da)

    Try
    '-*-> cn
    Dim cls As New clsGeneral
    cn.ConnectionString = cls.GetConnection
    cls = Nothing

    '-*-> cmd
    cmd.CommandText = "Select * From " & TblName
    If StrWhere.Trim <> "" Then cmd.CommandText = cmd.CommandText & " WHERE " & StrWhere
    cmd.Connection = cn

    '-*-> da
    da.SelectCommand = cmd

    '**************************************'
    If Not Insert And Not Update Then
    da.Fill(ds, TblName)
    End If
    '**************************************'
    If Insert Then
    da.InsertCommand = cBuilder.GetInsertCommand
    da.Update(ds.Tables(TblName))
    If retValue Then
    cmd.CommandText = "Select Max(Id) from " & TblName
    cn.Open()
    StrRetValue = cmd.ExecuteScalar
    cn.Close()
    End If
    End If
    '**************************************'
    If Update Then
    Dim value() As String = StrWhere.Split("*")
    cmd.CommandText = "UpDate " & TblName & " SET " & value(1) & " WHERE " & value(0)
    cn.Open()
    cmd.ExecuteNonQuery()
    cn.Close()
    End If

    Return ""
    Catch ex As Exception
    Return "OprationONTbl : " & ex.Message

    Finally
    If cn.State = ConnectionState.Open Then cn.Close()
    cn = Nothing
    cmd = Nothing
    da = Nothing
    cBuilder = Nothing
    End Try

    End Function

    Now i want get more table form my application and with transaction, that if i send to webService two tables, with one transaction tow tables be full of data,
    now i changed above web method but my result is not true ,i test to many state of this code but it has different Error for Inserting data,

    I don't know how i can change this web method for doing my work true.

    i write this but it is mistake,

    Dim myTblName() As String = TblName.Split("$")
    '-*-> cmd
    For i As Integer = 0 To myTblName.Length - 1
    cmd.CommandText = "Select * From " & myTblName(i)
    If StrWhere.Trim <> "" Then cmd.CommandText = cmd.CommandText & " WHERE " & StrWhere
    cmd.Connection = cn
    '-*-> da
    da.SelectCommand = cmd
    '**************************************'
    If Not Insert And Not Update Then
    da.Fill(ds, myTbl

    G 1 Reply Last reply
    0
    • S Saba02

      Hi all, I have one web methode in my web service,that can only get one table from my application and it is without Transaction,

      <WebMethod()> _
      Public Function OprationONTbl(ByRef ds As Data.DataSet, ByVal TblName As String, ByVal Insert As Boolean, ByVal Update As Boolean, ByVal StrWhere As String, ByVal retValue As Boolean, ByRef StrRetValue As String) As String
      Dim cn As New SqlConnection
      Dim cmd As New SqlCommand
      Dim da As New SqlDataAdapter
      Dim cBuilder As New SqlCommandBuilder(da)

      Try
      '-*-> cn
      Dim cls As New clsGeneral
      cn.ConnectionString = cls.GetConnection
      cls = Nothing

      '-*-> cmd
      cmd.CommandText = "Select * From " & TblName
      If StrWhere.Trim <> "" Then cmd.CommandText = cmd.CommandText & " WHERE " & StrWhere
      cmd.Connection = cn

      '-*-> da
      da.SelectCommand = cmd

      '**************************************'
      If Not Insert And Not Update Then
      da.Fill(ds, TblName)
      End If
      '**************************************'
      If Insert Then
      da.InsertCommand = cBuilder.GetInsertCommand
      da.Update(ds.Tables(TblName))
      If retValue Then
      cmd.CommandText = "Select Max(Id) from " & TblName
      cn.Open()
      StrRetValue = cmd.ExecuteScalar
      cn.Close()
      End If
      End If
      '**************************************'
      If Update Then
      Dim value() As String = StrWhere.Split("*")
      cmd.CommandText = "UpDate " & TblName & " SET " & value(1) & " WHERE " & value(0)
      cn.Open()
      cmd.ExecuteNonQuery()
      cn.Close()
      End If

      Return ""
      Catch ex As Exception
      Return "OprationONTbl : " & ex.Message

      Finally
      If cn.State = ConnectionState.Open Then cn.Close()
      cn = Nothing
      cmd = Nothing
      da = Nothing
      cBuilder = Nothing
      End Try

      End Function

      Now i want get more table form my application and with transaction, that if i send to webService two tables, with one transaction tow tables be full of data,
      now i changed above web method but my result is not true ,i test to many state of this code but it has different Error for Inserting data,

      I don't know how i can change this web method for doing my work true.

      i write this but it is mistake,

      Dim myTblName() As String = TblName.Split("$")
      '-*-> cmd
      For i As Integer = 0 To myTblName.Length - 1
      cmd.CommandText = "Select * From " & myTblName(i)
      If StrWhere.Trim <> "" Then cmd.CommandText = cmd.CommandText & " WHERE " & StrWhere
      cmd.Connection = cn
      '-*-> da
      da.SelectCommand = cmd
      '**************************************'
      If Not Insert And Not Update Then
      da.Fill(ds, myTbl

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Don't use Max(Id) and a transaction to get the id, just call "select scope_identity()" after you have made the insert. That is the normal method to get the id, and it will use less resources on the server.

      Despite everything, the person most likely to be fooling you next is yourself.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups