datagridview賦值問題
Private Sub Btnquery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnquery.ClickDim Query, Query1 As String
If strFlag = "add" Or strFlag = "edit" Then
If MessageBox.Show("現在是新增或修改狀態請確認是否退出", "提示", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
DataGridView1.ReadOnly = True
Else
Exit Sub
End If
End If
'query = DataGridView1.Item(0, inti).Value.ToString
DataGridView1.ReadOnly = True
If Txtid.Text <> "" Then
Query = Txtid.Text
Else
MessageBox.Show("條件起不可為空!")
Exit Sub
End If
If Txtid.Text <> "" Then
Query1 = Txtid1.Text
Else
MessageBox.Show("條件啟不可為空!")
Exit Sub
End If
Try
objdataAdapter = New SqlDataAdapter
objdataAdapter.SelectCommand = New SqlCommand
objdataAdapter.SelectCommand.Connection = objconnection
objdataAdapter. = "select id,name,address,price from t_table"
' where id between '" & Query & "' and '" & Query1 & "'"
objdataAdapter. = CommandType.Text
objDataset = New DataSet
If objconnection.State <> ConnectionState.Open Then
objconnection.Open()
Else
MessageBox.Show(ErrorToString)
MessageBox.Show("打不開")
End If
objdataAdapter.Fill(objDataset, "t_table")
objconnection.Close()
DataGridView1.AutoGenerateColumns = True '獲取表中的列
DataGridView1.DataSource = objDataset
DataGridView1.DataMember = "t_table"
ObjdataView = New DataView(objDataset.Tables("t_table"))
ObjcurrecyManager = CType(Me.BindingContext(ObjdataView), CurrencyManager)
Catch ex As Exception
MessageBox.Show(ErrorToString)
End Try
End Sub
以上代碼,有沒有辦法更改為,不從表中取列出來。而是由在前台加入datagridview的列後。再由代碼將表中的資料賦到對應的列上