hello :)

how to insert new record in grid view coming from textbox?

I tried to used the INSERT INTO -- sql query, but it didn't work..

does it have another way? please.

my current language is vb. thanks.

With mydataLupon
                .DataFile = "~/Database/dbLupon.mdb"
                .SelectCommand = "INSERT INTO tblLupon_C VALUES ('" & lblRegion_C.Text & "', '" & lblProvince.Text & "', '" & cmbCITYMUN.SelectedValue & "', '" & cmbBarangay.SelectedValue & "', '" & lblmyHide.Text & "', '" & txtLName.Text & "', '" & txtFName.Text & "', '" & txtmiddle.Text & "', '" & txtSuffix.Text & "', ' F ')"
                
                .SelectCommand = "SELECT  [COUNT_C], [POSITION_C], [LAST_M], [FIRST_M], [MIDDLE_M], [SUFFIX_M], [SEX_C] FROM tblLupon_C WHERE REGION_C = '" & lblRegion_C.Text & "' AND PROVINCE_C = '" & lblProvince.Text & "' AND CITYMUN_C = '" & cmbCITYMUN.SelectedValue & "' AND BARANGAY_C =  '" & cmbBarangay.SelectedValue & "'"
                
                MsgBox("saved")
            End With

please answer me :)
your help will mean a lot :) thanks

You don't need to use Insert into statement to show data in gridview.

You can directly store those data coming from textbox into DataTable by creating new DataRow and Add this DataRow to DataTable Rows collection.

Once you will add the row to DataTable, you need to bind your DataTable to Gridview..

hello :)

how to insert new record in grid view coming from textbox?

I tried to used the INSERT INTO -- sql query, but it didn't work..

does it have another way? please.

my current language is vb. thanks.

With mydataLupon
                .DataFile = "~/Database/dbLupon.mdb"
                .SelectCommand = "INSERT INTO tblLupon_C VALUES ('" & lblRegion_C.Text & "', '" & lblProvince.Text & "', '" & cmbCITYMUN.SelectedValue & "', '" & cmbBarangay.SelectedValue & "', '" & lblmyHide.Text & "', '" & txtLName.Text & "', '" & txtFName.Text & "', '" & txtmiddle.Text & "', '" & txtSuffix.Text & "', ' F ')"
                
                .SelectCommand = "SELECT  [COUNT_C], [POSITION_C], [LAST_M], [FIRST_M], [MIDDLE_M], [SUFFIX_M], [SEX_C] FROM tblLupon_C WHERE REGION_C = '" & lblRegion_C.Text & "' AND PROVINCE_C = '" & lblProvince.Text & "' AND CITYMUN_C = '" & cmbCITYMUN.SelectedValue & "' AND BARANGAY_C =  '" & cmbBarangay.SelectedValue & "'"
                
                MsgBox("saved")
            End With

please answer me :)
your help will mean a lot :) thanks

Does your code return any Errors ?

@ sir rohand, can you give me sample codes for datatables. :)
please sir.

@ sir vuyiswamb,thanks for the reply,

I made new codes but doesn't work :(

What Error do you get when you run your code ?

sir, I changed the code and it works.

my problem is the update code

Protected Sub Gridview1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
        
        Dim txtR, txtP, txtC, txtCo, txtB, txtL, txtF, txtM, txtPo, txtSu, txtS As TextBox
     
        Dim row As GridViewRow = GridView1.Rows(e.RowIndex)
        txtR = CType(row.Cells(1).Controls(0), TextBox)
        txtP = CType(row.Cells(2).Controls(0), TextBox)
        txtC = CType(row.Cells(3).Controls(0), TextBox)
        txtB = CType(row.Cells(4).Controls(0), TextBox)
        txtCo = CType(row.Cells(5).Controls(0), TextBox)
        txtPo = CType(row.Cells(6).Controls(0), TextBox)
        txtL = CType(row.Cells(7).Controls(0), TextBox)
        txtF = CType(row.Cells(8).Controls(0), TextBox)
        txtM = CType(row.Cells(9).Controls(0), TextBox)
        txtSu = CType(row.Cells(10).Controls(0), TextBox)
        txtS = CType(row.Cells(11).Controls(0), TextBox)
         
        Dim connection As OleDbConnection
        connection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\Karl Gennadi\Desktop\Visual Studio 2008\WebSite3\Database\dbLupon.mdb")
        
        
        Dim command As OleDbCommand
        command = New OleDbCommand("UPDATE tblLUPON_C SET POSITION_C = @POSITION_C, LAST_M = @LAST_M, FIRST_M = @FIRST_M, MIDDLE_M = @MIDDLE_M, SUFFIX_M = @SUFFIX_M, SEX_C = @SEX_C WHERE REGION_C = @REGION_C AND PROVINCE_C = @PROVINCE_C AND CITYMUN_C = @CITYMUN_C AND BARANGAY_C = @BARANGAY_C AND COUNT_C = @COUNT_C", connection)
        command.Parameters.AddWithValue("@REGION_C", txtR.Text)
        command.Parameters.AddWithValue("@PROVINCE_C", txtP.Text)
        command.Parameters.AddWithValue("@CITYMUN_C", txtC.Text)
        command.Parameters.AddWithValue("@BARANGAY_C", txtB.Text)
        command.Parameters.AddWithValue("@COUNT_C", txtCo.Text)
        command.Parameters.AddWithValue("@POSITION_C", txtCo.Text)
        command.Parameters.AddWithValue("@LAST_M", txtL.Text)
        command.Parameters.AddWithValue("@FIRST_M", txtF.Text)
        command.Parameters.AddWithValue("@MIDDLE_M", txtM.Text)
        command.Parameters.AddWithValue("@SUFFIX_M", txtSu.Text)
        command.Parameters.AddWithValue("@SEX_C", txtS.Text) 

        'Try
        connection.Open()

        command.ExecuteNonQuery()
        '  Catch ex As Exception
        'MsgBox(ex.ToString)
        ' Finally
        connection.Close()
        
        GridView1.EditIndex = -1
        Call BindGrid()
        'End Try
    End Sub

i understand that, but what Error are you getting ?

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.