Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:59:39+00:00 2026-05-31T00:59:39+00:00

I am making a invoice system in Visual Basic 2010 and i am stuck

  • 0

I am making a invoice system in Visual Basic 2010 and i am stuck here

Here is my code

     Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles btnDelete.Click

    For Each row As DataGridViewRow In datagrid.SelectedRows
        Dim selectedindex As String = datagrid.CurrentRow.Cells(0).Value.ToString()
        datagrid.Rows.Remove(row)
        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If
        Dim sql = "DELETE FROM sales WHERE InvoiceNo='" & txtInvoiceNo.Text & "' and id='" & selectedindex & "'"
        Dim cmd As New MySqlCommand(sql, conn)
        Dim reader As MySqlDataReader = cmd.ExecuteReader

        If reader.Read() Then

        End If
        conn.Close()
        reader.Close()
    Next

End Sub

This code is not working well please have a look to my invoice screen shot and suggest me a better code

When i try to delete the selected row the code does not work and if any one can tell me i can delete multiple selected rows? they are deleted from the datagrid but not from database

Sales Form

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:59:40+00:00Added an answer on May 31, 2026 at 12:59 am

    Try this:

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles btnDelete.Click
    
        Using cn As New MySqlConnection("Connection string here"), _
              cmd As New MySqlCommand("DELETE sales WHERE InvoiceNo= ?InvoiceNo and id= ?id", cn)
    
            cmd.Parameters.Add("?InvoiceNo", MySqlDbTypes.VarChar, 10).Value = txtInvoiceNo.Text
            cmd.Parameters.Add("?id", MySqlDbTypes.Int32)
    
            cn.Open()
            For Each row As DataGridViewRow In datagrid.SelectedRows
                cmd.Parameters(1).Value = row.Cells(0).Value
                cmd.ExecuteNonQuery()
                datagrid.Rows.Remove(row)
            Next row
    
        End Using
    
    End Sub
    

    It looks like you’re trying to save and re-use a single connection object, and just open it as needed. This is misguided: it breaks .Net’s ability to do connection pooling. You really do want to create a new connection object for each place where you’ll talk to the database. This also let’s you do a better job making sure a connection is closed properly after a bad query. Finally, the use of query parameters will guard your app against sql injection attacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am newbie to class and objects.Here I am making an application for invoice.So
I have a feeling I am making some sort of foolish mistake here, however
I'm making a invoice script but my query is returning al my entries mulpiple
I'm making a simple one-form Invoice bill printing, below is the screenshot to illustrate
I am building an invoice system, where I will use jQuery, to update fields.
I am making an invoicing system, with the support for multiple subsidaries which each
I am making a BI system for a bank-like institution. This system should manage
Lets take an example of WinForms applcation and making invoice. On the Invoice form
Making a system with my group in school and got a problem figuring out
Making a very basic paint program for a class and one of the requirements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.