Solved

vb.net 2008 Datagribview Add back to DB

Posted on 2009-04-06
6
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

615 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