Solved

vb.net 2008 Datagribview Add back to DB

Posted on 2009-04-06
6
209 Views
Last Modified: 2013-11-26
use dataset to populate datagribview. now i need to add a row in datagribview and in the same time it will add in the database
0
Comment
Question by:aarontham
  • 3
  • 2
6 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24078612
Hi aarontham,
But you will use the datagridview OR your custom form ?
0
 

Expert Comment

by:JeffatACS
ID: 24080085
Hi,

I have been researching this myself - here are a few bits of info I have found

1) search MSDN express free download

2) http://www.codeproject.com/KB/database/VB_DGV_UpdatingBoundDB.aspx  -- this maybe helpful

3) http://www.itwriting.com/pcw/vbdotnetdata.php  -- first link is to a simple database code download

Hope this might help.
0
 

Author Comment

by:aarontham
ID: 24083703
Hi Jpaulino

i use datagridview with the same code you provide for me to do the save button.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 48

Expert Comment

by:jpaulino
ID: 24084057
Ok, but do you will delete the records in the datagridview directly OR you have some textbox's, checkbox's, etc, to fill the information and then you have an insert button ?
If you will use the datagridview for that, the code I showed you will be enough. It saves also the add, delete and update actions.
0
 

Author Comment

by:aarontham
ID: 24084175


I have have some textbox's, checkbox's, etc, to fill the information and then do then do insert
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24084318
Then you just have to insert in the mySQL table. Here's an example for SQL and you only need to change the classes (SqlConnection to mySQLCommand, etc)
        ' Add this Imports to the top of the page
        Imports System.Data.SqlClient
 
        Dim myConnectionString As String = _
              "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\myDatabase.mdf';" & _
              ";Integrated Security=True;User Instance=True"
 
        ' Defines the T-SQL command
        Dim SQL As String = "INSERT INTO myTable([username], [date]) VALUES (@username, @date);"
 
        ' Create a new connectio class
        Using connection As New SqlConnection(myConnectionString)
 
            ' Creates the command that will do the T-SQL
            Using command As New SqlCommand(SQL, connection)
 
                ' Add's the parameters that will be inserted
                command.Parameters.Add("@username", SqlDbType.VarChar).Value = "jpaulino"
                command.Parameters.Add("@date", SqlDbType.DateTime).Value = DateTime.Now
 
                connection.Open()
 
                ' Executes the command
                Dim x As Integer = command.ExecuteNonQuery()
                If x < 1 Then
                    MessageBox.Show("No records inserted.")
                End If
 
            End Using
 
        End Using

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question