.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Insert the data to sql server database.

Posted By:laptop charles       Posted Date: July 25, 2010    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  

Insert the data to sql server database using Vb.net
 

*Create the data base using sql server.
*Copy the bellow coding then run.
*It contain two textbox and two label.
*The text box name is txt1 and txt2.
*One button name is insert.
*Then give the connection string.
*Type the data on this textbox then click to insert.
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim dr As SqlDataReader
 Private Sub insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles insert.Click
        cmd = New SqlCommand("insert into charl values(@Data1,@Data2) ", con)
        cmd.Parameters.AddWithValue("@Data1", txt1.Text)
        cmd.Parameters.AddWithValue("@Data2", txt2.Text)
        cmd.ExecuteNonQuery()
        MsgBox("Successfully inserted ")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con = New SqlConnection("server=ANONYMOUS;Trusted_Connection=yes;database=charles")
        con.Open()
    End Sub
End Class



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend