Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


I cant add data into my sqldatabase


I cant add data into my sqldatabase

Author
Message
rocks_lp
rocks_lp
Forum God
Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)

Group: Forum Members
Posts: 5, Visits: 27
i amusing visual studio 2005.

i have initialized my connection in a module.

conn is the name of my connection



this is the Code



Public Class frmCreditNoteRequest

Dim adapter As SqlDataAdapter

Dim cmd As SqlCommand

Dim ds As New DataSet



Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click



Dim test As Boolean

Dim sql As String

sql = "INSERT INTO CreditNoteDetails (RequestedDate,CusId,Details,RequestedAmount) VALUES ('11-10-2008',2,'test',3000.00);"



conn.Open()



MsgBox("conection has open")



test = conn.State 'to check the connection state



MsgBox(test)





cmd = New SqlCommand(sql, conn)



conn.Close()



adapter = New SqlDataAdapter



adapter.InsertCommand = cmd



MsgBox("You have successflly updated")



End Sub

End Class



[size=5]



What is wrong in this coding plz help meeeeeeeeeeeeeeeee[/size]
Edited
12/21/2008 by rocks_lp
MaslowB
MaslowB
Forum God
Forum God (9.7K reputation)Forum God (9.7K reputation)Forum God (9.7K reputation)Forum God (9.7K reputation)Forum God (9.7K reputation)Forum God (9.7K reputation)Forum God (9.7K reputation)Forum God (9.7K reputation)Forum God (9.7K reputation)

Group: Forum Members
Posts: 55, Visits: 63
to do an insert you could do this:



cmd.ExeNonQuery



right after this line:



cmd = New SqlCommand(sql, conn)

Vb.net 2005, Teradata, Sql Server 2005, mainframe automation
toxiod
toxiod
Forum God
Forum God (8.2K reputation)Forum God (8.2K reputation)Forum God (8.2K reputation)Forum God (8.2K reputation)Forum God (8.2K reputation)Forum God (8.2K reputation)Forum God (8.2K reputation)Forum God (8.2K reputation)Forum God (8.2K reputation)

Group: Forum Members
Posts: 39, Visits: 225


hi,



based to what i see in your code you close the connection before the actual insert command which is really not work put the conn.Close() after the adapter.InsertCommand = cmd



toxiod



visit: www.toxiod.noadsfree.com
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search