Click here to Skip to main content
15,894,287 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Its possible for auto generate specific column values in datagridview?
Example: There are two tables(first,second) to link with separate forms. First and second table some fields may equal values. Second table can be connect with datagridview. In datagridview specific fields(same) values can be automatically generated (values from first table).
Its possible in datagridview ?
Posted
Comments
[no name] 28-Nov-11 5:32am    
please clarify the question so we could help immediately.
ckulasekaran 28-Nov-11 7:51am    
how to retrieve data from other database table to datagridview

While fetcing the data from database you can use joins to get data from diffrent tables.

Or in datalayer you can create the data source using LINq or creating whatever datatable structure values you want
 
Share this answer
 
You can not automatically generate values in DataGridView.
You can achive this by writting some queries releted your database.

Check this :
VB
Public Function AutoID(ByVal fieldname As String, ByVal table As String)
        objda.SelectCommand.CommandText = "select max(cint(mid(" & fieldname & ",4,len(" & fieldname & ")))) as maxval from " & table
        Try
            Dim maxId As Object = objda.SelectCommand.ExecuteScalar
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        If maxID Is DBNull.Value Then                       'If Database Table is Empty
            Return 1                                        'Set Enquiry Id 1
        Else
            Try
                dr = objda.SelectCommand.ExecuteReader      'Execute Query
            Catch ex As Exception
                MessageBox.Show(ex.ToString)                'Providing Error Message
            End Try
            If dr.Read Then                                 'Read dr
                If dr(0) Is DBNull.Value Then               'Converting dr value to String
                    Return 1                                'Set Id to 1
                Else
                    Return (dr(0) + 1)                      'Increasing ID by 1
                End If
            End If
            dr.Close()                                      'Closeing data reader
        End If
    End Sub

How to Use : Call it on Form_Load event
VB
txtIdFiled.Text=AutoID("FieldName", "TableName")   'Generating Auto EnrollmentId
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900