Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings,
i have started to learn Visual Basic recently and i need some help please in how to add more quantity to the already stored in Database with a different button than the one i already use to add products i will insert the code which used to insert new product in datagridview below:
and thanks in advance. ^_^


below is the code used for the insert button

What I have tried:

VB
    Private Sub insertData()
    'تعريف متغيير جديد لمعرفة المجلد الخاص بالبرنامج
    Dim newdir As String = System.Windows.Forms.Application.StartupPath
    Dim اسم_المنتج As String = TextBox1.Text
    Dim الكمية As String = TextBox2.Text
    Dim اسم_المستخدم As String = TextBox3.Text
    Dim تاريخ_الادخال As String = DateTimePicker1.Text
    'الاعلان عن متغيير و تعيين جملة الادخال لقاعدة البيانات كقيمة له
    Dim query As String = "Insert into product values (@اسم_المنتج , @الكمية , @اسم_المستخدم , @تاريخ_الادخال)"
    'الاعلان عن متغيير و تعيين جملة الاتصال بقاعدة البيانات كقيمة له
    Using conn As SqlConnection = New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFilename=" & newdir & "\Database1.mdf; Integrated Security=True")
        'الاعلان عن متغيير تنفيذى للاتصال و ادخال البيانات للقاعدة
        Using cmd As SqlCommand = New SqlCommand(query, conn)
            'اعطاء قيم للمتغير التنفيذى
            cmd.Parameters.AddWithValue("@اسم_المنتج", اسم_المنتج)
            cmd.Parameters.AddWithValue("@الكمية", الكمية)
            cmd.Parameters.AddWithValue("@اسم_المستخدم", اسم_المستخدم)
            cmd.Parameters.AddWithValue("@تاريخ_الادخال", تاريخ_الادخال)
            'فتح الاتصال بالقاعدة
            conn.Open()
            'تنفيذ الاتصال و الادخال لقاعدة البيانات
            cmd.ExecuteNonQuery()
            'اغلاق الاتصال بالقاعدة
            conn.Close()
        End Using
    End Using
End Sub
Posted
Updated 28-May-21 18:22pm

1 solution

If I understand your question correctly, you can use UPDATE statement to update an existing row in the database.

For more information, see UPDATE (Transact-SQL) - SQL Server | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900