Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,058 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,726 people online right now. Registration is fast and FREE... Join Now!




Problem in Deleting in VB.Net

 
Reply to this topicStart new topic

Problem in Deleting in VB.Net

Sonia B
24 Feb, 2008 - 09:35 PM
Post #1

New D.I.C Head
*

Joined: 24 Feb, 2008
Posts: 12

For adding a new record using command builder i have used the following code:

CODE

Dim conString As String = "Data Source= Ankita; Initial Catalog=Ankita; Integrated Security=True"
        Dim conn As SqlConnection = New SqlClient.SqlConnection(conString)
        Dim str As String
        str = "Select * from RawMaterial"
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(str, conn)
        Dim sc As New SqlCommand
        Dim cb As New SqlCommandBuilder(da)
        Dim NewRow As DataRow
        Dim inc As Integer

        da.Fill(ds, "RawMaterial")


        If inc <> -1 Then
            NewRow = ds.Tables("RawMaterial").NewRow()
            NewRow.Item("RawMaterialCode") = cboRawMaterialCode.Text
            NewRow.Item("RawMaterialName") = txtRawMaterialName.Text
            NewRow.Item("RawMaterialManufacturer") = txtManufacturer.Text
            NewRow.Item("RawMaterialQuantity") = txtQuantityofRawMaterial.Text
            NewRow.Item("RawMaterialRate") = txtRawMaterialRate.Text
            'NewRow.Item("DateofPurchase") = txtDateofPurchase.Text

            ds.Tables("RawMaterial").Rows.Add(NewRow)
            da.Update(ds, "RawMaterial")
            MsgBox("New Record added to the Database")



It Works Perfectly.

For deleting i have used the following code:

CODE

  'Dim conString As String = "Data Source= Ankita; Initial Catalog=Ankita; Integrated Security=True"
        'Dim conn As SqlConnection = New SqlClient.SqlConnection(conString)
        'Dim Str As String
        'Str = "Select * from RawMaterial"
        'Dim ds As New DataSet
        'Dim da As New SqlDataAdapter(Str, conn)
        'Dim cb As New SqlCommandBuilder(da)
        'da.Fill(ds, "RawMaterial")

        'ds.Tables("RawMaterial").Rows(0).Delete()
        'da.Update(ds, "RawMaterial")
        'MsgBox("Record has been deleted from the Database")


But i dont want this code because it deletes as per the row specified in the following line.
"'ds.Tables("RawMaterial").Rows(0).Delete()"

I want to delete as per the Item selected in the combo box using command builder as i did the adding.
Please help.
User is offlineProfile CardPM
+Quote Post

sonu5588
RE: Problem In Deleting In VB.Net
27 Feb, 2008 - 08:09 PM
Post #2

New D.I.C Head
*

Joined: 3 Feb, 2008
Posts: 3

Hello Good Morning..
Sonya how are you ..

There is the solution of Your code ..
Copy this code and paste where u have to use.


'Dim conString As String = "Data Source= Ankita; Initial Catalog=Ankita; Integrated Security=True"
'Dim conn As SqlConnection = New SqlClient.SqlConnection(conString)
'Dim Str As String
'Str = "Delete from RawMaterial 'Somevalue in Table' "

'MsgBox("Record has been deleted from the Database"
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Problem In Deleting In VB.Net
27 Feb, 2008 - 08:26 PM
Post #3

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
ds.Tables("RawMaterial").Rows(0).Delete()
You're going to have to change the '0' to the number of the row you want to delete. Try looking at the combo box's SelectedIndex property.

This post has been edited by Nayana: 27 Feb, 2008 - 08:29 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 10:33PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month