I am working in VB 2005. I want user input in textboxes. On user last textbox lost focus all data entered inthe textboxes shold shift to datagridview. User input as many data as he want. when he finish all his enteries. Click on save butto all data of datagridview insert into sql server 2000 database. Any one help

My Code As :

Imports System.data
Imports System.data.SqlClient

Public Class frmpurchase
    Public con As String
    Public MyConn As New SqlClient.SqlConnection
    Private SQLSelect, SQLInsert As String
    Private da As System.Data.SqlClient.SqlDataAdapter
    Private ds As New System.Data.DataSet
    Private m_ds As New DataSet()
    Private dtl As New Data.DataTable


Private Sub frmpurchase_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        dtl.TableName = "Purchse_Sub"

      
        dtl.Columns.Add("PartNo")
        dtl.Columns.Add("Description")
 
        m_ds.Tables.Add(dtl)

        da.Fill(m_ds)
        
	DataGridView1.DataSource = m_ds.Tables(0)

    End Sub


Private Sub TextBox2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox9.LostFocus
        Dim newrow As DataRow
        newrow = m_ds.Tables(0).NewRow
        newrow.Item(0) = TextBox1.Text
        newrow.Item(1) = TextBox2.Text
        m_ds.Tables(0).Rows.Add(newrow)
        da.Update(m_ds)
        DataGridView1.Refresh()
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
	con = "Data Source="";Initial Catalog="";User ID=sa"
        MyConn = New SqlClient.SqlConnection(con)
        If MyConn.State = ConnectionState.Broken Or MyConn.State = ConnectionState.Closed Then
            MyConn.Open()
        End If
da.Update(m_ds)
End Sub
End Class

First of all, you need to use code tags. You can do this by typing:
[code=vb] 'your code goes here

[/code].
This will make your code more clear and easier to read and debug. Please repost using code tags.

Imports System.data
Imports System.data.SqlClient

Public Class frmpurchase
Public con As String
Public MyConn As New SqlClient.SqlConnection
Private SQLSelect, SQLInsert As String
Private da As System.Data.SqlClient.SqlDataAdapter
Private ds As New System.Data.DataSet
Private m_ds As New DataSet()
Private dtl As New Data.DataTable


Private Sub frmpurchase_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

dtl.TableName = "Purchse_Sub"


dtl.Columns.Add("PartNo")
dtl.Columns.Add("Description")

m_ds.Tables.Add(dtl)

da.Fill(m_ds)

DataGridView1.DataSource = m_ds.Tables(0)

End Sub


Private Sub TextBox2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox9.LostFocus
Dim newrow As DataRow
newrow = m_ds.Tables(0).NewRow
newrow.Item(0) = TextBox1.Text
newrow.Item(1) = TextBox2.Text
m_ds.Tables(0).Rows.Add(newrow)
da.Update(m_ds)
DataGridView1.Refresh()
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
con = "Data Source="";Initial Catalog="";User ID=sa"
MyConn = New SqlClient.SqlConnection(con)
If MyConn.State = ConnectionState.Broken Or MyConn.State = ConnectionState.Closed Then
MyConn.Open()
End If
da.Update(m_ds)
End Sub

End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.