Click here to Skip to main content
15,891,136 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionVB 2005 Express Edition Pin
aswd22-Feb-09 17:53
aswd22-Feb-09 17:53 
AnswerRe: VB 2005 Express Edition [modified] Pin
drexler_kk22-Feb-09 18:55
drexler_kk22-Feb-09 18:55 
GeneralRe: VB 2005 Express Edition Pin
aswd23-Feb-09 1:34
aswd23-Feb-09 1:34 
GeneralRe: VB 2005 Express Edition Pin
EliottA23-Feb-09 3:08
EliottA23-Feb-09 3:08 
GeneralRe: VB 2005 Express Edition Pin
aswd23-Feb-09 3:11
aswd23-Feb-09 3:11 
GeneralRe: VB 2005 Express Edition Pin
EliottA23-Feb-09 3:13
EliottA23-Feb-09 3:13 
GeneralRe: VB 2005 Express Edition Pin
Dave Kreskowiak23-Feb-09 4:04
mveDave Kreskowiak23-Feb-09 4:04 
QuestionProblem with DataGridView Pin
drexler_kk22-Feb-09 17:06
drexler_kk22-Feb-09 17:06 
Hi all,I'm having problem here with my code. I would like to Update the Database with my DataGridView1 when Click the Button1. But from the code below,I found that an Error have occured.

Error from Visual Studio 2008= System.Data: Missing the DataColumn 'DO_No'in the DataTable 'Main_table' for the SourceColumn 'DO_No'.

The following are the code I load the data from database to my DataGridView1:
Private Sub MaintainDO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ObjMyConn = New MySqlConnection(MyConnString)

       
        SQL = "SELECT * FROM main_table"
        Try

            ObjMyConn.Open()
            ObjAdapter = New MySqlDataAdapter(SQL, ObjMyConn)
            ObjComBuilder = New MySqlCommandBuilder(ObjAdapter)
            ds = New DataSet
            ObjAdapter.Fill(ds, "Main_table")
            dt = ds.Tables("Main_table")
            dt.Columns(0).ColumnName = "Date"
            dt.Columns(1).ColumnName = "DO No."
            dt.Columns(2).ColumnName = "Lorry No."
            dt.Columns(3).ColumnName = "Load From"
            dt.Columns(4).ColumnName = "To Site"
            dt.Columns(5).ColumnName = "Company Name"
            dt.Columns(6).ColumnName = "Item Description"

            DataGridView1.DataSource = dt.DataSet.Tables("Main_table")
            DataGridView1.Refresh()
        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly)
        Finally
            ObjMyConn.Close()
        End Try
    End Sub


The code I put inside my Button1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        SQL = "SELECT * FROM main_table"
        Try
            ObjAdapter.Update(ds.Tables("Main_table")) '<< Here is how I used to update my database.

            ds.Tables("Main_table").Clear()
            DataGridView1.DataSource = Nothing
            DataGridView1.Refresh()

            ObjMyConn.Open()
            ObjAdapter = New MySqlDataAdapter(SQL, ObjMyConn)
            ObjComBuilder = New MySqlCommandBuilder(ObjAdapter)
            ObjAdapter.Fill(ds, "Main_table")
            dt = ds.Tables("Main_table")

            dt.Columns(0).ColumnName = "Date"
            dt.Columns(1).ColumnName = "DO No."
            dt.Columns(2).ColumnName = "Lorry No."
            dt.Columns(3).ColumnName = "Load From"
            dt.Columns(4).ColumnName = "To Site"
            dt.Columns(5).ColumnName = "Company Name"
            dt.Columns(6).ColumnName = "Item Description"

            DataGridView1.DataSource = ds.Tables("Main_table")
            DataGridView1.Refresh()
        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly)
        Finally
            ObjMyConn.Close()
        End Try


    End Sub


Besides,I have a few other question to know more about my coding style suits my need of the project. This are my question:
1. Am I using a right way to put the data into the datagridview? Any other way is better for me to control the data inside the datagridview?
2. If I need to add another column which shows abit calculation (suck like column1 x column2=>>new column9)into the datagridview,how should I do?

Thanks for reading my post,hope someone can give me some sample for this solution. Thank you again~!
AnswerRe: Problem with DataGridView Pin
Dave Kreskowiak23-Feb-09 2:08
mveDave Kreskowiak23-Feb-09 2:08 
AnswerRe: Problem with DataGridView Pin
drexler_kk23-Feb-09 16:28
drexler_kk23-Feb-09 16:28 
Questionlabel Pin
aswd22-Feb-09 16:03
aswd22-Feb-09 16:03 
AnswerRe: label Pin
Mycroft Holmes22-Feb-09 16:15
professionalMycroft Holmes22-Feb-09 16:15 
AnswerRe: label Pin
Tom Deketelaere22-Feb-09 22:42
professionalTom Deketelaere22-Feb-09 22:42 
GeneralRe: label Pin
aswd23-Feb-09 1:29
aswd23-Feb-09 1:29 
GeneralRe: label Pin
Tom Deketelaere23-Feb-09 1:42
professionalTom Deketelaere23-Feb-09 1:42 
GeneralRe: label Pin
aswd23-Feb-09 1:47
aswd23-Feb-09 1:47 
GeneralRe: label Pin
Tom Deketelaere23-Feb-09 2:07
professionalTom Deketelaere23-Feb-09 2:07 
GeneralRe: label Pin
aswd23-Feb-09 15:15
aswd23-Feb-09 15:15 
GeneralRe: label Pin
Tom Deketelaere23-Feb-09 20:47
professionalTom Deketelaere23-Feb-09 20:47 
GeneralRe: label Pin
CPallini23-Feb-09 2:55
mveCPallini23-Feb-09 2:55 
GeneralRe: label Pin
Tom Deketelaere23-Feb-09 3:04
professionalTom Deketelaere23-Feb-09 3:04 
Questionhow to get reset an application without reopen the application? Pin
aswd22-Feb-09 15:52
aswd22-Feb-09 15:52 
AnswerRe: how to get reset an application without reopen the application? Pin
Mycroft Holmes22-Feb-09 16:16
professionalMycroft Holmes22-Feb-09 16:16 
AnswerRe: how to get reset an application without reopen the application? Pin
dan!sh 22-Feb-09 20:20
professional dan!sh 22-Feb-09 20:20 
QuestionEvents in vb.net Pin
udikantz22-Feb-09 15:23
udikantz22-Feb-09 15:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.