Solved

vb.net 2008 Datagribview Add back to DB

Posted on 2009-04-06
6
210 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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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