Solved

vb.net 2008 Datagribview Add back to DB

Posted on 2009-04-06
6
212 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net figure out error 3 47
how to remove error in database 6 55
EF5 How do I stop pre-compiled views? 8 54
Difference between Leaflet and MapBox? 5 47
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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