Solved

vb.net 2008 Datagribview Add back to DB

Posted on 2009-04-06
6
206 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now