i made if statement in my programs that allow the user to choose days...
at first if my NewEveryCount.ToString is = 1, it will successfully load what field i want to display in my datagridview (that is rot1, ot1 and etc). but when im going to click the button again and change change my NewEveryCount.ToString = 2. it will just add another column for rot2, ot2 and so on and so fort. in short my column will idnumber employeename rot1 ot1 rot2 ot2Code:Private Sub cmdsummaryview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsummaryview.Click ClearGridView() '----> this stands for Clearing the Datagrid If NewEveryCount.ToString = 1 Then SQL = "SELECT `idnumber`, `employeename`, `rot1`, `ot1` FROM `employeewithperiod` WHERE `mdclientperiod`='" + MD5CalcString(cmbclient.Text + "-" + txtcperiod.Text) + "' ORDER BY employeename ASC" ElseIf NewEveryCount.ToString = 2 Then SQL = "SELECT `idnumber`, `employeename`, `rot2`, `ot2` FROM `employeewithperiod` WHERE `mdclientperiod`='" + MD5CalcString(cmbclient.Text + "-" + txtcperiod.Text) + "' ORDER BY employeename ASC" endif myCommand.CommandText = SQL myCommand.Connection = MySQLConnectionString myAdapter.SelectCommand = myCommand myBuilder = New MySql.Data.MySqlClient.MySqlCommandBuilder(myAdapter) myAdapter.Fill(myDataSet, "employeewithperiod") myBindingSource.DataSource = myDataSet.Tables("employeewithperiod") DataGridView1.DataSource = myBindingSource DataGridView1.Refresh() End Sub Public Sub ClearGridView() myDataSet.Clear() myDataSet.Dispose() myBindingSource.DataSource = myDataSet DataGridView1.DataSource = myBindingSource 'DataGridView1.DataSource = myDataSet DataGridView1.DataSource = Nothing End Sub
hmmm i dont know what's wrong with my datagrid.. that's why im thinking if im going to leave my datagrid and move to listview.. but i want to explore datagridview.. hope any one can give me a hand for this.. thanks guys


LinkBack URL
About LinkBacks




Reply With Quote

Bookmarks