TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chintan Shah
NA
1
0
Inserting Record using Data Adepter.Update() Command
Mar 4 2008 3:33 PM
I created a Table in SQL Server 2005 and now i am creating an application to directly manipulate this table so i wrote this code and the commented part works successfully but part before it is not running it gives following Exception
"Update requires a valid UpdateCommand when passed DataRow collection with modified rows."
Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim dr As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM dbo.Categories", SqlCon)
dr.InsertCommand = New SqlCommand("INSERT INTO dbo.Categories VALUES('@CategoryName',@CategoryID)", SqlCon)
dr.InsertCommand.Parameters.Add("@CategoryName", SqlDbType.VarChar, 15, "CategoryName")
dr.InsertCommand.Parameters.Add("@CategoryID", SqlDbType.Int, 6, "CategoryID")
Dim DT As New DataTable
dr.Fill(DT)
Dim rw As DataRow = DT.Rows(0)
rw(0) = TextBox2.Text
rw(1) = TextBox1.Text
dr.Update(DT)
'Dim cmd As SqlCommand = New SqlCommand("INSERT INTO dbo.Categories(CategoryName,CategoryID) " + "VALUES('" + TextBox2.Text + "'," + TextBox1.Text + ")", SqlCon)
'cmd.Parameters.Add("@CategoryName", SqlDbType.VarChar, 15, "CategoryName")
'cmd.Parameters.Add("@CategoryID", SqlDbType.Int, 6, "CategoryID")
'cmd.ExecuteNonQuery()
End Sub
Reply
Answers (
2
)
How to catch the CH button of a Microsoft Remote Control ?
Insert Into error(solved)