I am working with windows application.
I have a datagrid in vb.net. Its first column is a checkbox. I want to know which checkboxes are checked and which are not.
My code is :
Dim dr As DataGridViewRow
For i = 0 To gdStudInfo.RowCount - 1
dr = gdStudInfo.Rows(i)
att = dr.Cells(0).Value.ToString()
If att.Equals("Present") Then
qry = "insert into Stu_Att_Detail values(" & id & "," & gdStudInfo.Rows(i).Cells(1).Value.ToString() & ",'" & dr.Cells(0).Value.ToString() & "')"
con.MyQuery(qry)
End If
Next
I am getting correct values for all checked check box, but it gets error when the checkbox is not checked.
What if you try this?
If Not String.IsNullOrEmpty(dr.Cells(0).Value) Then
'do stuff here
End If
Related
pls help me.. i already done try to call my database to datagrid, but now i can't find a way to delete my data from selected row at datagrid
my datagrid from here
Private Sub cmdTampil_Click()
AdoCupu.ConnectionString = Buka
AdoCupu.RecordSource = "Select * from vJadwalRehab Where jadwalrehab between '" & Format(dtDari, "yyyy/MM/dd") & "' and '" & Format(dtpSampai, "yyyy/MM/dd") & "'"
AdoCupu.Refresh
Set dgData.DataSource = AdoCupu
End Sub
i tried these methods on 'delete button' but still won't work
Private Sub cmdHapus_Click()
1.method 'dgData.(1).index
dgData.rows.RemoveAt (i)
'dgData.Delete
2.method ' Dim index As Integer
' index = dgData.CurrentCell.RowIndex
3.method ' delete the selected row
' dgData.rows.RemoveAt (index)
'If Not dgData.CurrentRow.IsNewRow Then
'dgData.rows.Remove (dgData.CurrentRow)
'End If
End Sub
i tried those 3 method but didn't work..
i found it! just delete index number'primary key' from table n row of data gone..
CONN.BeginTrans
CONN.Execute "delete jadwalRehab where id='" & txtID & "'"
CONN.CommitTrans
ShowData
MsgBox "Data Jadwal Berhasil Dihapus!"
Once you fill in your grid, the easy way of deleting records is through the Adodc control:
Private Sub cmdHapus_Click()
Dim bm As Variant
For Each bm In dgData.SelBookmarks
AdoCupu.Recordset.Bookmark = bm
AdoCupu.Recordset.Delete
Next
End Sub
I have to change a very old application written in Vb6 with Data Report.
Actually displays a query records with only one field named txtdata.
Now I would display always one field (txtdata) but with different text size and style depending on whether it starts with a # or not.
I thought to check records for records if it starts with # or not and set text style and size for each record.
How can I do?
Dim rs As Adodb.Recordset
Dim sql As String
Dim regtratt As
.................
' I have a Data Report with textbox named txtdata in Section1
sql = ""
sql = sql + "SELECT txtdata "
sql = sql + "FROM journal "
sql = sql + "WHERE cod=421 "
sql = sql + "ORDER BY id "
Set rs = xOpenRecordset(sql, cnOnline)
If rs.RecordCount > 0 Then
Set regtratt.DataSource = rs
regtratt.DataMember = ""
' I want to change the font according to the text but I don't know how to because DataSource=rs takes the records.
'If InStr("#", regtratt.Sections("Section1").Controls(1).Item.Value) Then
' regtratt.Sections("Section1").Controls(1).Font.size = 20
' regtratt.Sections("Section1").Controls(1).Font.Bold = True
'End If
regtratt.Orientation = rptOrientLandscape
regtratt.WindowState = vbMaximized
regtratt.Font.Name = "courier new"
regtratt.Refresh
regtratt.Show vbModal
Unload regtratt
Else
MsgBox ("Sorry No data")
End If
Hi Everyone I am having trouble getting a ComboBox to sort, when another combobox is selected.
I think I have the Right SQL Syntax but I cant seem to get the vba to run it through; currently the vba returns all of the states in the recordset regardless of the company.
Private Sub CboCountry_Click()
Set db = CurrentDb
Dim SQLStr As String
Set RsState = db.OpenRecordset("T2States", dbOpenSnapshot, dbSeeChanges)
'populates combobox with recordset, that is defined by the country input from the form
RsState.MoveFirst
Do While Not RsState.EOF
Me.CboState.RowSource = Me.CboState.RowSource & RsState("StateID") & ";" & RsState("State") & ";"
RsState.MoveNext
Loop
I think this is the right SQL String but I'm having trouble to get it to work.
'SQLStr = "SELECT T2States.StateID, T2States.States, T2States.CountryID" & _
" FROM T2States GROUP BY T2States.StatesID" & _
" WHERE T2States.CountryID = """ & Me.CboCountry.Value & """"
Any help will be greatly appreciated.
Edit#1
See Full Code below, the error that pops up when I substitute SQLStr into the Openrecordset is a Run-time error '3078' the microsoft access database engine cannot find the input table or query 'SQLStr'. Make sure it exists and that its name is spelled correctly.
What should happen is when a country is selected from CboCountry combobox, it will load the CboState combobox by sorting the recordset by CountryID
see below for both code parts
Private Sub Form_Load()
Set db = CurrentDb
Set RsCompany = db.OpenRecordset("T1Company", dbOpenDynaset, dbSeeChanges)
Set RsCountry = db.OpenRecordset("T2Countries", dbOpenSnapshot, dbSeeChanges)
Set RsAddress = db.OpenRecordset("T1Addresses", dbOpenDynaset, dbSeeChanges)
Set RsAddressType = db.OpenRecordset("T2AddressType", dbOpenSnapshot, dbSeeChanges)
Set RsCompanyAddress = db.OpenRecordset("T3Company_Address", dbOpenDynaset, dbSeeChanges)
Me.CboCountry = Null
Me.TxtAddress1 = Null
Me.TxtAddress2 = Null
Me.TxtAddress3 = Null
Me.TxtCity = Null
Me.CboAddressType = Null
Me.CboCountry = Null
Me.CboState = Null
Me.TxtPostalCode = Null
Me.TxtCompanyID = Null
Me.TxtLegalName = Null
Me.TxtNickname = Null
Me.TxtAddressID = Null
RsCountry.MoveFirst
Do While Not RsCountry.EOF
Me.CboCountry.RowSource = Me.CboCountry.RowSource & RsCountry("CountryID") & ";" & RsCountry("Country") & ";"
RsCountry.MoveNext
Loop
RsAddressType.MoveFirst
Do While Not RsAddressType.EOF
Me.CboAddressType.RowSource = Me.CboAddressType.RowSource & RsAddressType("AddressTypeID") & ";" & RsAddressType("AddressType") & ";"
RsAddressType.MoveNext
Loop
Me.TxtLegalName.SetFocus
End Sub
Private Sub CboCountry_Click()
Set db = CurrentDb
Dim SQLStr As String
'SQLStr = "SELECT T2States.StateID, T2States.State, T2States.CountryID" & _
" FROM T2States" & _
" WHERE T2States.CountryID = """ & Me.CboCountry.Value & """"
Set RsState = db.OpenRecordset("T2States", dbOpenDynaset, dbSeeChanges)
'populates combobox with recordset, that is defined by the country input from the form
RsState.MoveFirst
Do While Not RsState.EOF
Me.CboState.RowSource = Me.CboState.RowSource & RsState("StateID") & ";" & RsState("State") & ";"
RsState.MoveNext
Loop
End Sub
Let us see
1- sure you've to append with
Having T2States.States, T2States.CountryID
2- Error exist in it, extra 's' in the Column name:
GROUP BY T2States.StatesID
3- put all the code and i'll check with you what you miss.
best regards
This one turned out to be a quick fix in the Property Sheet under the DATA tab, the Row Source Type had to be changed back to 'Table/Query' from a 'Value'.
There is VBA that could account for this but it was just a simple as changing that Row Source.
The Reason for the mix up, for a quick bit of background if it helps, is that all my combo boxes are unbound and I was binding them with VBA Recordsets so the rowsource has to be a value list - Essentially the VBA is writing the list everytime it loads.
Where as when I started using SQL to generate the recordset, even though it was in VBA I had to change the property back to Table/Query.
Thanks.
I'm using vb6, SQL Server2008, and ComponentOne Objects. I'm using the following code to copy the grid results to the clipboard:
Set rs = AdoMain.Recordset.Clone
For Each row In GridMain.SelBookmarks
rs.Bookmark = row
'For col = gridMain.SelStartCol To gridMain.SelEndCol
For Col = 0 To 15
strTemp = strTemp & rs(Col).Value & vbTab
Next Col
strTemp = strTemp & vbCrLf
Next row
Clipboard.Clear
Clipboard.SetText strTemp, vbCFText
This portion works great for the "body" of the grid, however I cannot get the grid headers to copy. Any help?
If you want the Name of recordset column use:
rs(col).Field.Name
but if you want the Header of GridMain column you should use
GridMain.Columns(col).Caption
If you are using VSFlexGrid, I think this will work:
With GridMain
'select entire grid
.Select .FixedRows, .FixedCols, .Rows - 1, .Cols - 1
'copy selection to clipboard
.Copy
End With
This requests for help follows a poorly worded request for help earlier (apologies).
I have two asp/vbscript pages. The second page (containing only <% vbscript %> is called when a form on the first page is submitted.
The code on the second page causes an update to a database record and is as follows (the fields are populated from querystring variables.):
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "dsn=xxx;uid=xxx;password=xxx;"
SQLString = "UPDATE dbo_tbl_printing_tempstore SET " & fieldPrefix & "has_text1 = 'YES', " & fieldPrefix & "text = '" & fieldUpdate & "' WHERE id = " & tempid & ""
MyConn.Execute(SQLString)
MyConn.Close
Set MyConn = Nothing
All the form submit does is to cause the database update to happen - nothing else.
The page then response.redirects back to the calling page. This causes a refresh and lot of data on the first page to be lost - this is what I'm trying to avoid.
Can someone please tell me how I can carry out the update without leaving and then refreshing the calling page please? I've been told Ajax can do this but I have no experience at all of using it.
Many thanks
First of all, change your code to use parameters so you will be protected against SQL Injection attack:
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "dsn=xxx;uid=xxx;password=xxx;"
SQLString = "UPDATE dbo_tbl_printing_tempstore SET " & fieldPrefix & "has_text1 = 'YES', " & fieldPrefix & "text = ? WHERE id = ?"
Set MyCommand = Server.CreateObject("ADODB.Command")
Set MyCommand.ActiveConnection = MyConn
MyCommand.CommandType = 1
MyCommand.CommandText = SQLString
MyCommand.Parameters.Append(MyCommand.CreateParameter("#text", 200, 1, 0, fieldUpdate))
MyCommand.Parameters.Append(MyCommand.CreateParameter("#id", 3, 1, 0, tempid))
MyCommand.Execute()
MyConn.Close
Set MyCommand = Nothing
Set MyConn = Nothing
Having this, the next step is adding hidden frame in the first page:
<iframe id="MyFrame" name="MyFrame" style="display:none;"></iframe>
And finally simply add target to your <form> tag like this:
<form action="SecondPage.asp" target="MyFrame">
That's it... now the form will be submitted "inside" the hidden frame, will still trigger the database update and won't cause any refresh.