how can i add row to table of sql with vb.net code?

asp.net.getting-started 91979 articles. 4 followers. Follow

3 Replies
1006 Views

Similar Articles

[PageSpeed] 33
Get it on Google Play
Get it on Apple App Store

 You can use System.Data.SqlClient classes :

 

        Using con As New SqlConnection(" your connection string goes here ")
            Dim com As New SqlCommand("Insert into Person (id,name) values(@id,@name) ", con)
            com.Parameters.AddWithValue("@id", 1)
            com.Parameters.AddWithValue("@name", "Nomi1")
            com.Connection.Open()

            Dim Inserted As Boolean = com.ExecuteNonQuery > 0

        End Using
  
Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
12/25/2008 12:41:37 PM

 

using the follwoing code

Public Function SaveData(ByVal strQuery As String) As Boolean

 

Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("conString").ConnectionString

Dim con As New SqlConnection(strConnString)

Dim cmd As New SqlCommand(strQuery, con)

cmd.CommandType = CommandType.Text

Try

con.Open()

cmd.ExecuteNonQuery()

Return True

Catch ex As Exception

Return False

Finally

con.Close()

cmd.Dispose()

sda.Dispose()

End Try

End Function


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
12/25/2008 12:43:51 PM

thank you very much!

it's work!

0
nomi1
12/25/2008 1:08:03 PM
Reply: