Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   just 1 question.. answer me pls.. hehehe (http://www.go4expert.com/forums/1-question-answer-pls-hehehe-t23141/)

cire09 30Aug2010 17:43

Code:

Imports System.Data.SqlClient
Public class form1
    Public con As New SqlConnection ("DateSource=.\SQLEXPRESS;AttachDbFilename=E:\sqlprog2\labexer\labexer\database2.mdf;Integrated Security=True;Connect Timeout=10;UserInstance=True")
    Public da As New SqlDataAdapter
    Public ds As DataSet
    DataSet = New DataSet
    Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.Close
        End
    End Sub
   
    Private Sub Button1_Click(byVal sender As System.Object, ByVal e As
System.Event Args) Handles Button1.Click
        addForm.Show()
        Me.Hide()
    End Sub
   
    Public Sub Form1_Load(ByVal sender As System.Object,ByVal e As
System.Event Args) Handles MyBase.Load
        'TODO: This line of code loads data into the
    'Database2DataSet.Product' table. You can move, or remove it, as
    needed.
            'Me.ProductTableAdapter.Fill(Me.Database2Dataset.Product)
            Try
                con.Open()
                ds.Clear()
                da = New SqlDataAdapter("Select * from Product", con)
                da.Fill(ds, "Product")
                DataGridView1.DataSource = ds.Tables("Product").DefaultView
            Catch ex as Exception
                MsgBox (ex.Message)
            Finally
                con.Close()
            End try
        End Sub
       
        Private Sub DataGridView_CellClick(ByVal sender As Object, ByVal e
    As System.Windows.Forms.DataGridViewCellEventArgs) Handles
    DataGridView1.CellClick
            Dim a As Integer
            Dim sql As String
            Try
                con.Open
                a = DataGridView1.Item(0,
    DataGridView1.CurrentRow.Index).Value
                sql = "select * from Products where Prod_id ='" & a & "'"
                da = New SqlDataAdapter(sql, con)
                da.Fill(ds, "Product Edit")
                editForm.TextBox1.Text = ds.Tables("Product
    Edit ").Rows(0).Item(0).ToString"
                editForm.TextBox2.Text = ds.Tables("Product
    Edit ").Rows(0).Item(1).ToString"
                editForm.TextBox3.Text = ds.Tables("Product
    Edit ").Rows(0).Item(2).ToString"
                editForm.TextBox4.Text = ds.Tables("Product
    Edit ").Rows(0).Item(3).ToString"
            Catch ex As Exception
                MsgBox (ex.Message)
            Finally
                con.Close()
            End Try
        End Sub
       
        Private Sub Button3_Click(ByVal sender As System.Object, By Val e As
    System.EventArgs) Handles Button3.Click
            con.Open()
            Dim sqlDeleteProduct As String
            Dim a As Integer
            Dim db As SqlCommand
            Dim answer As Integer
            a = DataGridView1.Item(0, DataGridView1.CurrentRow.Index).Value
            answer =  MsgBox("Do you want to delete the product?",
    MsgBoxStyle.YesNo + MsgBoxStyle.Question, "")
            If answer = vbYes Then
                sqlDeleteProduct = "delete from Product where Prod_id = " &
    a & ""
                db = New SqlCommand(sqlDeleteProduct, con)
                db.ExecuteNonQuery()
                MsgBox("Record Deleted!", MsgBoxStyle.Information, "")
                ds.Clear()
                da = New SqlDataAdapter("Selcet * from Product", con)
                da.Fill(ds, "Product")
                DataGridView.DataSource = ds.Tables("Product").DefaultView
            End If
            con.Close()
        End Sub
       
        Private Sub Button2_Click(ByVal sender as System.Object, ByVal e As
    System.EventArgs) Handles Button2.Click
            editForm.Show()
        End Sub
        Private Sub Button5_Click(ByVal sender as System.Object, ByVal e As
    System.EventArgs) Handles Button5.Click
        Dim db As New SqlCommand
        ds.Clear()
        da = New SqlDataAdapter("select * from Product where Prod_id =
    " & TextBox1.Text & "", con)
        da.Fill(ds, "product")
        DataGridView1.DataSource = ds.Tables("Product").DefaultView
    End Sub
End Class
   
       
       
        Imports Sytem.Data.SqlClient
        Public Class addForm
            Public con As New SqlConnection("Data
        Source=.\SQLEXPRESS;AttachDbfilename=C:\Documents and
        Settings\student.Lab\Desktop\sqlprog2\labexer\labexer\Database2.mdf;Int
        egrated Security=True;Connect Timeout=10;User Instance=True")
            Public da As New SqlDataAdapater
            Public ds As DataSet = New DataSet
            Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
        system.EventArgs) Handles Button2.Click
                Me.Close()
                Form1.Form1_Load(sender, e)
            End Sub
           
            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
        System.EventArgs) Handles Button1.Click
                Dim db As SqlCommand
                Try
                con.Open()
                Dim sqlAddProduct As String
                sqlAddProduct = "Insert into Product"
        (Prod_id,Prod_name,Prod_price,Prod_qty) values(" & TextBox1.Text & ",
        '" & TextBox2.Text & "', " & TextBox3.Text & ", " &TextBox4 .Text & ")"
                db = New SqlCommand(sqlAddProduct, con)
                db.ExecuteNonQuery()
                MsgBox ("Record Saved!", MsgBoxStyle.Information, "")
                TextBox1.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                TextBox4.Text = ""
            Catch ex As Exception
                MsgBox (ex.Message)
            Finally
                ds.Reset()
                con.Close()
            End Try
        End Sub
       
        Private Sub addForm_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
   
        End Sub
    End Class
   
   
   
   
    Imports System.Data.SqlClient
    Public Class editForm
        Public con As New SqlConnection("Data
    Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and
    Settings\student.LAB\Desktop\sqlprog2\labexer\labexer\Database2.mdf;Int
    egrated Security=True;Connect Timeout=10;User Instance=True")
        Public da As New SqlDataAdapater
            Public ds As DataSet = New DataSet
            Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
        system.EventArgs) Handles Button2.Click
                Call Form1.Form1_Load(sender, e)
                Me.Close()
            End Sub
           
            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
        System.EventArgs) Handles Button1.Click
                Dim sqlEditProduct As String
                Dim db As New SqlCommand
                Try
                    con.Open()
                    sqlEditProduct = "update Product set Prod_name = '" &
        TextBox2.Text & "', Prod_price= " & TextBox3.Text & ", Prod_qty = '" &
        TextBox4.Text & "' where prod_id = " & TextBox1.Text & ""
                    db= New SqlCommand(sqlEditProduct, con)
                    db.ExecuteNonQuery()
                    MsgBox("Record Saved!", MsgBoxStyle.Information, "")
                Catch ex As Exception
                    MsgBox (ex.Message)
                Finally
                    ds.Reset()
                    con.Close()
                End Try
            End Sub
            Private Sub ContextMenuScript1_Opening(ByVal sender As
        System.Object, ByVal e As System.ComponentModel.CancelEventArgs)
        Handles ContextMenuStrip1.Opening
       
        End Sub
        End Class
       
           
Private Sub Form_Load()

End Sub

uhm.. i have dis source code... can u pls tell me what version of VB i will use?

uhm.. i am currently using vb6 for this source code.. and i have a feeling that the version that is using is not the correct one..

virxen 31Aug2010 03:34

Re: just 1 question.. answer me pls.. hehehe
 
Quote:

Imports System.Data.SqlClient
Public Class editForm
vb6 do not use imports ,this code is for sure visual basic .net (vb2008 for example)

ManzZup 31Aug2010 09:46

Re: just 1 question.. answer me pls.. hehehe
 
ya .net for sure

kien_vn 31Aug2010 12:36

Re: just 1 question.. answer me pls.. hehehe
 
I think can use visual studio .net 2005 to compiled

cire09 6Sep2010 23:00

Re: just 1 question.. answer me pls.. hehehe
 
thx for ur help.. people in this site sure helps me alot.. thank you for sharing ur knowledge.. uhm sori for l8 reply


All times are GMT +5.5. The time now is 17:55.