Click here to Skip to main content
15,905,136 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionThreading Problem Pin
pdnet21-Oct-08 22:07
pdnet21-Oct-08 22:07 
AnswerRe: Threading Problem Pin
Eduard Keilholz22-Oct-08 0:04
Eduard Keilholz22-Oct-08 0:04 
GeneralRe: Threading Problem Pin
pdnet22-Oct-08 1:12
pdnet22-Oct-08 1:12 
AnswerRe: Threading Problem Pin
N a v a n e e t h22-Oct-08 2:26
N a v a n e e t h22-Oct-08 2:26 
GeneralRe: Threading Problem Pin
pdnet22-Oct-08 19:05
pdnet22-Oct-08 19:05 
GeneralRe: Threading Problem Pin
Dave Kreskowiak23-Oct-08 1:57
mveDave Kreskowiak23-Oct-08 1:57 
AnswerRe: Threading Problem Pin
Dave Kreskowiak22-Oct-08 4:55
mveDave Kreskowiak22-Oct-08 4:55 
QuestionProblem With Get More Table Instead of one Table Pin
Saba0221-Oct-08 22:02
Saba0221-Oct-08 22:02 
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, myTblName(i))
End If
Next

'**************************************'
If Insert Then
Dim trans As SqlTransaction
cn.Open()
trans = cn.BeginTransaction
cmd.Transaction = trans

For i As Integer = 0 To myTblName.Length - 1
da.InsertCommand = cBuilder.GetInsertCommand
da.Update(ds.Tables(myTblName(i)))

If retValue Then
cmd.CommandText = "Select Max(Id) from " & myTblName(i)
StrRetValue = cmd.ExecuteScalar

End If
Next

Try
trans.Commit()
Catch ex As Exception
trans.Rollback()
End Try

End If
'**************************************'
If Update Then
cn.Open()
Dim trans As SqlTransaction
trans = cn.BeginTransaction
cmd.Transaction = trans
For i As Integer = 0 To myTblName.Length - 1
Dim value() As String = StrWhere.Split("*")
cmd.CommandText = "UpDate " & myTblName(i) & " SET " & value(1) & " WHERE " & value(0)
cmd.ExecuteNonQuery()

Next
Try
trans.Commit()
Catch ex As Exception
trans.Rollback()
End Try
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

i need your help,

Thank You 

<div class="ForumSig">Hoda </div>

AnswerRe: Problem With Get More Table Instead of one Table Pin
Guffa21-Oct-08 22:24
Guffa21-Oct-08 22:24 
Questionlinklabel Pin
hitesh.kalra21-Oct-08 20:40
hitesh.kalra21-Oct-08 20:40 
AnswerRe: linklabel Pin
Rupesh Kumar Swami21-Oct-08 21:49
Rupesh Kumar Swami21-Oct-08 21:49 
AnswerRe: linklabel Pin
jzonthemtn22-Oct-08 1:22
jzonthemtn22-Oct-08 1:22 
QuestionUnhandled Exception Pin
Tauseef A21-Oct-08 16:58
Tauseef A21-Oct-08 16:58 
AnswerRe: Unhandled Exception Pin
Colin Angus Mackay21-Oct-08 22:51
Colin Angus Mackay21-Oct-08 22:51 
QuestionText Boxes Print Preview Pin
jagdishg21-Oct-08 9:11
jagdishg21-Oct-08 9:11 
AnswerRe: Text Boxes Print Preview Pin
Dave Kreskowiak21-Oct-08 10:32
mveDave Kreskowiak21-Oct-08 10:32 
GeneralRe: Text Boxes Print Preview Pin
jagdishg21-Oct-08 12:22
jagdishg21-Oct-08 12:22 
GeneralRe: Text Boxes Print Preview Pin
Dave Kreskowiak22-Oct-08 4:49
mveDave Kreskowiak22-Oct-08 4:49 
QuestionNeed advice with WshNetwork PLEASE Pin
Trey549821-Oct-08 8:54
Trey549821-Oct-08 8:54 
AnswerRe: Need advice with WshNetwork PLEASE Pin
Dave Kreskowiak21-Oct-08 10:24
mveDave Kreskowiak21-Oct-08 10:24 
GeneralRe: Need advice with WshNetwork PLEASE Pin
Trey549822-Oct-08 2:04
Trey549822-Oct-08 2:04 
GeneralRe: Need advice with WshNetwork PLEASE Pin
Dave Kreskowiak22-Oct-08 4:34
mveDave Kreskowiak22-Oct-08 4:34 
GeneralRe: Need advice with WshNetwork PLEASE Pin
Trey549822-Oct-08 5:05
Trey549822-Oct-08 5:05 
GeneralRe: Need advice with WshNetwork PLEASE Pin
Dave Kreskowiak22-Oct-08 6:37
mveDave Kreskowiak22-Oct-08 6:37 
QuestionNeed Help on Custom Action Installer Pin
Saseendran Kombath21-Oct-08 8:19
Saseendran Kombath21-Oct-08 8:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.