1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to add record inside the table

Discussion in 'C#' started by kharearch, Apr 19, 2008.

  1. #1
    I am new to dot net. I want to addd a record inside the table using oledb. Can somebody give me code. How to add record. code which I am trying is following -


    Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\arch.mdb")
    Dim objcommand As OleDb.OleDbCommand = New OleDb.OleDbCommand()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    objcommand.Connection = conn

    objcommand.CommandText = "insert into my(name,age,dept)VALUES (@name,@age,@dept);"
    objcommand.Parameters.Add("@name", TextBox1.Text)
    objcommand.Parameters.Add("@age", TextBox2.Text)
    objcommand.Parameters.Add("@dept", TextBox1.Text)
     
    kharearch, Apr 19, 2008 IP
  2. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #2
    You shouldn't create your SQL statements directly from user input. Create variables and clean them for SQL injection first.
     
    itcn, Apr 22, 2008 IP