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

Recommended Answers

All 2 Replies

you didn't have server...

New SqlConnection("server=;database=tempdb;uid=;pwd=")

what is your server name??

you are missing some '
every item must be wrapped in -- ' --

so like 'value','value2'

doesn't look like your textbox.text has ' on both ends.

hope that helps...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.