Command doesnt insert

0 views
Skip to first unread message

mary

unread,
Jul 29, 2006, 4:15:21 AM7/29/06
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi friends
the code below runs without exeception error, but after running this
code i saw that no line has been inseerted to variz table.


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If User.Identity.IsAuthenticated Then
Label4.Text = User.Identity.Name

Else
Label6.Visible = True
TextBox1.Enabled = False
Button1.Enabled = False
End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)


Dim conn As New
SqlConnection(ConfigurationManager.ConnectionStrings("WroxUnitedConnectionString").ConnectionString)
Dim trans As SqlTransaction = Nothing
Dim cmd As New SqlCommand()
Dim cmd1 As New sqlcommand()


Try
conn.Open()
trans = conn.BeginTransaction
cmd.Connection = conn

cmd.Transaction = trans


' set the order details

cmd.CommandText = "INSERT INTO variz(membername,
variz, varizdate) " & _
"VALUES ('" & User.Identity.Name & "'," &
TextBox1.Text & "," & Date.Today & " )"

cmd.ExecuteNonQuery()

Catch ex As Exception

End Try



End Sub

Mike Roberts

unread,
Jul 29, 2006, 8:23:32 AM7/29/06
to DotNetDe...@googlegroups.com
Mary,
 
I see you begin a transaction, do you ever commit it?
 
Mike

 

mary

unread,
Jul 29, 2006, 10:13:24 AM7/29/06
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi friend
I change my codes to below, it looks ok with no error but when i return
back to DB I find out that there is no line added to DB.
----------------------------------------------------------------------------------------------------------------------------
ALTER PROCEDURE dbo.storedvariz
(
@MemberName varchar(50),
@Variz money

)
AS


INSERT INTO variz(membername, variz, varizdate)

VALUES (@MemberName, @Variz, GETDATE())

----------------------------------------------------------------------------------------------------------------------


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim conn As New
SqlConnection(ConfigurationManager.ConnectionStrings("WroxUnitedConnectionString").ConnectionString)
Dim trans As SqlTransaction = Nothing

Dim cmd As New SqlCommand("storedvariz", conn)
Try


cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@MemberName",
User.Identity.Name)
cmd.Parameters.AddWithValue("@Variz", TextBox1.Text)

conn.Open()
cmd.ExecuteNonQuery()
conn.Close()

mary

unread,
Jul 30, 2006, 1:05:59 AM7/30/06
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi friends after deleting transaction my problem solved!!!!!!

Reply all
Reply to author
Forward
0 new messages