DataBinding list view - asp.net

Dim _tableBackLogs As System.Data.DataTable
Do While i - 2 > 0
_tableBackLogs = Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester='" & i - 2 & "'")
i = i - 2
Loop
lvBackSubjects.DataSource = _tableBackLogs
lvBackSubjects.DataBind()
Doing this binds only the data with the last value of i supplied to the ListView.I want all the data.Suppose i=5 . So i want the ListView to have data for i=3,1.Hope i am not confusing you guys.

Looks like the loop is overwriting the variable _tableBackLogs. Probably better off doing something like this:
dim semesters as New System.Text.StringBuilder()
Do While i - 2 > 0
semesters.Append("'" & i & "',")
i = i - 2
Loop
' remove the last ,
semesters.Remove(semesters.Length -1,1)
_tableBackLogs = Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester in (" & semesters.ToString() & ")"

Related

How to Insert Other Language(Like French,Chinese) Characters From ASP.NET Gridview to the Oracle Table

I am having some tables data which is having French, Chinese language characters.
ex: ENTRÉÉ D25 SBS RAL 7035 MG
I can able to show these tables data in gridview with same language and i am able to generate the query based on number of rows from gridview dynamically which is correct.
If insert from SQL Developer tool it is inserting correctly, if the query is executed from .net it is going in English characters.
Ex: ENTRÉÉ D25 SBS RAL 7035 MG this is inserting as ENTREE D25 SBS RAL 7035 MG
I am generating the queries dynamically because each time my gridview columns will change.
For j = 1 To totcols - 1
If Right(GridWFOwner.HeaderRow.Cells(j).Text, 4) = "PREV" Then
ElseIf GridWFOwner.HeaderRow.Cells(j).Text = "CHANGE_INFO" Then
Else
SQL_COL = SQL_COL & "," & GridWFOwner.HeaderRow.Cells(j).Text
SQL_VAL = SQL_VAL & ",LTRIM(RTRIM('" & Trim(Replace(Replace(Server.HtmlDecode(row.Cells(j).Text), "'", "''"), " ", "")) & "'))"
End If
Next
SQL_COL = Mid(SQL_COL, 2, Len(SQL_COL))
SQL_VAL = Mid(SQL_VAL, 2, Len(SQL_VAL))
SQL_COL = "ETL_ID," & SQL_COL & "," & "REQUEST_NO,DC_CODE,USER_ID,INSERT_TS"
If ACTION_FLAG = "I" Then
TOT_SQL = "INSERT INTO DVLX.TABEL1(" & SQL_COL & ") VALUES(SEQ_MAT.NEXTVAL," & SQL_VAL & "," & "'" & uprno & "'" & ",'IBR'," & "'" & Session("user_id") & "'" & ",sysdate)"
Else
TOT_SQL = "INSERT INTO DVLX.TABEL1(" & SQL_COL & ") VALUES(SEQ_MAT.NEXTVAL," & SQL_VAL & "," & "'" & uprno & "'" & ",'IBR'," & "'" & Session("user_id") & "'" & ",sysdate)"
End If
Dim cmdi As OracleCommand
cmdi = New OracleCommand(TOT_SQL, cnOra)
cmdi.ExecuteNonQuery()

Insert looped variable to one table column

I have Checkbox form and I am trying to save my loops values into a variable.
This is how I am looping:
For i = 1 to Request.Form("packages").count
Set packnamn = ObjConn.Execute ("Select * from services_package where id='"&
Request.Form("packages")(i) &"'")
panamn = packnamn("name") & "-"
Response.write panamn
Next
This will output
Greece-English-Spanish-
Now im trying to save the whole output in my MySQL. But i'm only getting the last value of the loop (Spanish-), This is my insert code.
Dim sql1
sql1= "insert into tariff_plan(package)"
sql1=sql1 & " VALUES "
sql1=sql1 & "('" & panamn &"')"
on error resume next
ObjConn.Execute sql1,recaffected
if err<>0 then
Response.Write(err.description)
else
response.write "Saved"
End if
You have to add the values to a variable where you are doing the response.write and do the insert after the loop.
panamn = ""
For i = 1 to Request.Form("packages").count
Set packnamn = ObjConn.Execute ("Select * from services_package where id='"&
Request.Form("packages")(i) &"'")
panamn = panamn & packnamn("name") & "-"
Next
Response.write panamn
'Do the insert here

Get all selected values from uniqueID CheckBoxList in VB.NET

I have create a list of CheckBoxList like that:
DDL.ID = "DDL_" & SelectedCategory & "_" & SubAssy & "_" & ProductType
RBL.ID = "RBL_" & SelectedCategory & "_" & SubAssy & "_" & ProductType
CBL.ID = "CBL_" & SelectedCategory & "_" & SubAssy & "_" & ProductType
ID from DDL.ID generate like that: CBL_Seatbel_General_General
How get all selected values by this unique ID?
I find a solutin for another people:
Dim GeneralCBL As CheckBoxList = gvr.FindControl("CBL_Seatbelt_General_General")
Dim Count0 As Integer = GeneralCBL.Items.Count
For i = 0 To Count0 - 1
If GeneralCBL.Items(i).Selected = True Then
Else
End If
Next

Add Rows to a DataTable without losing the previous rows

Dim _tableBackLogs As System.Data.DataTable
Do While i - 2 > 0
_tableBackLogs = Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester='" & i - 2 & "'")
i = i - 2
Loop
Doing this replaces the previous data in the DataTable. I want to retain the previous data i.e i want the new rows to be added to the DataTable w/o replacing the previous rows.
Replace your code with following.
Dim _tableBackLogs As New System.Data.DataTable
Do While i - 2 > 0
_tableBackLogs.Merge(Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester='" & i - 2 & "'"))
i = i - 2
Loop
Use Merge method
Dim _tableBackLogs As System.Data.DataTable
Do While i - 2 > 0
_tableBackLogs.Merge(Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester='" & i - 2 & "'"))
i = i - 2
Loop

asp pagination problem

Hi i have a problem with this asp pagination. it seems to be putting all the links in the one row, so i think it might have something to do with the check of the int i...
but im not that familar with asp. can anyone shed any light on this problem.
the folders contain pdfs for each day of the month, named A08P2.pdf A09P2.pdf etc...
Thanks
i = 1
Set fc = f.Files
Set ff = f.SubFolders
For Each f1 in fc
intPage = cint(mid(f1.name,2,2))
chrEdition = mid(f1.name,1,1)
if chrEdition = "A" then
if i = 1 then
Response.Write "<tr>"
end if
Response.Write "<td width='40' align='center'><a href=" & sUP & f1.name & " class='blue_11px'>" & intPage & "</a></td>"
if i = 10 then
Response.Write "</tr>"
i = 0
end if
end if
i = i + 1
Next
You should move the incrementing of the i (i=i+1) inside the if...end if, since if i is 9 and you encounter two chrEditions that are not 'A' then i will become 11 and will never match the closing condition i=10:
if chrEdition = "A" then
if i = 1 then
Response.Write "<tr>"
end if
Response.Write "<td width='40' align='center'><a href=" & sUP & f1.name & " class='blue_11px'>" & intPage & "</a></td>"
if i = 10 then
Response.Write "</tr>"
i = 0
end if
i = i + 1
end if

Resources