hello , i want to add new record ino database ,but getting some problem pl help me
front end :- VB.net2003
back end :- SQL Server 2000
my efforts :
Imports System.Data.SqlClient
Imports System.Data
Dim conn As SqlConnection = _
New SqlConnection("server=;database=tempdb;uid=;pwd=")
Dim ds As New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter("select city_id,city from t_city", conn)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn.Open()
da.Fill(ds, "t_city")
conn.Close()
End Sub
Private Sub BTNINSERT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNINSERT.Click
Dim objcommand As New SqlCommand
Dim str As String
conn.Open()
objcommand.Connection = conn
str = "insert into t_city(city_id,city) values(" & txtid.Text & ",'" & txtcity.Text & "')"
objcommand.CommandText = str
Dim dv As DataView
dv = New DataView(ds.Tables("t_city"))
conn.Close()
txtid.DataBindings.Add("text", dv, "city_id")
txtcity.DataBindings.Add("text", dv, "city")
MsgBox("connection set up")
End sub