I am creating a project in which I have to show all the columns of database table named LMTS_compatibility in a datagrid. How can I do it in VB.NET

I am able to connect but cannot enter the values in datagrid and display it.
Please Help!!!!!!!!!
:icon_cry:

Dani AI

Generated

Short practical plan for : populate the DataGrid from MySQL with a simple bind routine, then handle editing with Edit/Update/Cancel handlers. was correct to point at EditCommand (set the grid into edit mode and rebind); the missing pieces are a safe Bind method and an Update handler that writes back to MySQL.

Example bind routine (uses Connector/NET):

Imports MySql.Data.MySqlClient

Private Sub BindGrid()
    Dim cs As String = "Server=localhost;Database=yourdb;Uid=youruser;Pwd=yourpass;"
    Using cn As New MySqlConnection(cs)
        Dim da As New MySqlDataAdapter("SELECT * FROM LMTS_compatibility", cn)
        Dim ds As New DataSet()
        da.Fill(ds)
        DataGrid1.DataSource = ds.Tables(0)
        DataGrid1.DataBind()
    End Using
End Sub

Markup and update pattern (use a TemplateColumn for reliable value retrieval; AutoGenerateColumns helps display but is fragile for updates):

<asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False"
    OnEditCommand="DataGrid1_EditCommand"
    OnUpdateCommand="DataGrid1_UpdateCommand"
    OnCancelCommand="DataGrid1_CancelCommand">
  <Columns>
    <asp:BoundColumn DataField="id" HeaderText="ID" />
    <asp:TemplateColumn HeaderText="Name">
      <ItemTemplate><%# Eval("name") %></ItemTemplate>
      <EditItemTemplate><asp:TextBox ID="txtName" runat="server" Text='<%# Bind("name") %>' /></EditItemTemplate>
    </asp:TemplateColumn>
    <asp:ButtonColumn ButtonType="Link" CommandName="Edit" Text="Edit" />
  </Columns>
</asp:DataGrid>

Update handler pattern (grab controls with FindControl, use parameterized UPDATE):

Protected Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs)
    Dim id As String = e.Item.Cells(0).Text
    Dim tb As TextBox = CType(e.Item.FindControl("txtName"), TextBox)
    Dim newName As String = tb.Text

    Using cn As New MySqlConnection(cs)
        cn.Open()
        Dim cmd As New MySqlCommand("UPDATE LMTS_compatibility SET name=@n WHERE id=@id", cn)
        cmd.Parameters.AddWithValue("@n", newName)
        cmd.Parameters.AddWithValue("@id", id)
        cmd.ExecuteNonQuery()
    End Using

    DataGrid1.EditItemIndex = -1
    BindGrid()
End Sub

Troubleshooting notes: always use a primary key in the WHERE clause; prefer TemplateColumns (or switch to GridView for easier DataKey handling); parameterize queries to avoid SQL injection; ensure MySql.Data is referenced. Background docs: DataGrid class documentation and MySQL Connector/NET docs. For a higher-level walkthrough consider the GridView editing guide: .

For : list table columns with DESCRIBE LMTS_compatibility or query information_schema.columns if a column list is needed programmatically.

I am creating a project in which I have to show all the columns of database table named LMTS_compatibility in a datagrid. How can I do it in VB.NET

I am able to connect but cannot enter the values in datagrid and display it.
Please Help!!!!!!!!!
:icon_cry:

I have got it.
But now I want to edit the datagrid during the runtime.
How can I do it ???:icon_sad:
Please Help!!!!!!!

In property builde u have buttom column in that edit,update,column s i there
take that
In propertis u have EditCommand double click onit
then write this code in that
Protected Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
Call bind()
End Sub

Hi bro... Can I knw hw U get to view all the attribute in database in specific table.


I am creating a project in which I have to show all the columns of database table named LMTS_compatibility in a datagrid. How can I do it in VB.NET

I am able to connect but cannot enter the values in datagrid and display it.
Please Help!!!!!!!!!
:icon_cry:

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.