sameer001 0 Newbie Poster

Hi,
i have problem that i cant see data in data base. code has no error. i dont know whats wrong. i m using Visual Studio 2008.

Imports System.Data.SqlClient
Public Class frmpurchase
    Dim cmd, cmd1, cmd2, cmd3, cmd4 As New SqlClient.SqlCommand
    Dim adp, adp1, adp2 As New SqlDataAdapter
    Dim dset, dset1, dset2 As New DataSet
    Dim tab, tab1, tab2 As New DataTable

    Dim dbProvider As String
    Dim dbSource As String
    Dim sql As String

    Dim con As New SqlConnection

    Dim dcode As String
   

    Private Sub frmpurchase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\vim.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        'TODO: This line of code loads data into the 'VimDataSet.purchase' table. You can move, or remove it, as needed.

        Me.PurchaseTableAdapter.Fill(Me.VimDataSet.purchase)

    End Sub

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Dim check As Integer
        Dim con As New SqlConnection
        Try
            con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\vim.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            con.Open()

            cmd = New System.Data.SqlClient.SqlCommand()
            cmd.Connection = con
            sql = ("select * from purchase")
            adp = New SqlClient.SqlDataAdapter(sql, con)
            If Chk_Fields() = True Then
                Dim bill As String = txtbillno.Text
                Dim bike As String = cmbo.Text
                Dim qt As Integer = Val(txtqty.Text)
                Dim rt As Integer = Val(txtrate.Text)                            
                Dim tot As Integer = qt * rt
                Dim pudate As Date = DateTimePicker1.Text

                cmd = New SqlCommand("INSERT INTO purchase VALUES('" & bill & "','" & bike & "','" & qt & "','" & rt & "','" & tot & "','" & pudate & "')", con)

                adp.InsertCommand = cmd

                ' DEBUG: DUMP INSERT STATEMENT
                MsgBox(adp.InsertCommand().CommandText)
                ' /DEBUG

               adp.InsertCommand.ExecuteNonQuery()

                check = cmd.ExecuteReader.RecordsAffected()
                If check > 0 Then
                    MsgBox("succesfully added", MsgBoxStyle.OkOnly, "Message :")
                    btnsave.Enabled = False
                Else
                    MsgBox(" failure to added", MsgBoxStyle.OkOnly, "Message :")
                End If
                con.Close()
            End If
        Catch


        Finally
            cmd = Nothing
            con.Close()
            con = Nothing
        End Try
   End Sub
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.