I am running into a problem where I am needing to accomplish something, but have never had experience with it before. I am currently running an asp site and using SQL Server for the database. I have a report that I takes the querysting from the filters page and then gives the information based on the querstring. It is an intake report, so there should only be a single line item and record per client hat appears in the report. On the report it gives information such as the date of first contact, and when the client started services with us. I am adding a new field to the report called services. It is possible and more common that there are many services to one client. Here is what I am needing to accomplish. I need for each service for that client to be listed in a single data cell on the report, without displaying multiple line items for that client. I was thinking that the answer may be accomplished by using BOF and EOF, but I am not sure how to take a stab at it. Here is the RecordSet that is already on the report, which contains every field with the exception of the new field, because I have tried to create a new RecordSet for that Field. Below are images that will hopefully give the idea of what I want to accomplish. Thank you so much for your input!
This image is what It looks like now... I want to put all of the services that show for aa aa to be in a single data cell rather than creating a new line for each service provided.
Image of what It looks like now.
This is an image I created in photoshop to show what I am really wanting it to look like.
This is a rough idea of What I want it to look like.
Here is the code so far.
<%
Dim rsClients
Dim rsClients_numRows
Set rsClients = Server.CreateObject("ADODB.Recordset")
rsClients.ActiveConnection = MM_ims_db_STRING
rsClients.Source = "SELECT" _
& " vClients.ClientID" _
& ", vClients.AgencyID" _
& ", vClients.OfficeID" _
& ", vClients.OfficeName" _
& ", vClients.LastName" _
& ", vClients.FirstName" _
& ", vClients.ClientTeamName" _
& ", vClients.EnrolledDate" _
& ", vClients.Agency" _
& ", ReferralSources.ReferralSourceID" _
& ", ReferralSourceText" _
& ", ReferralTypeID" _
& ", ReferralSources.ReferralSource" _
& ", ReferralType" _
& ", vClients.DataEntryDate" _
& ", vClients.DataEntryDays" _
& ", ReferralStaffID" _
& ", ReferralStaffName" _
& ", DataEntryStaffID" _
& ", Staff_1.FirstName + ' ' + Staff_1.LastName AS DataEntryStaffName" _
& ", vClients.Intake1stContactStaffID" _
& ", Staff.FirstName + ' ' + Staff.LastName AS Intake1stContactStaffName" _
& ", vClients.Intake1stContactAssignedDate" _
& ", vClients.Intake1stContactCompletedDate" _
& ",vClients. Intake1stScheduledStaffID" _
& ", Staff_2.FirstName + ' ' + Staff_2.LastName AS Intake1stScheduledStaffName" _
& ", vClients.Intake1stScheduledAssignedDate" _
& ", vClients.Intake1stScheduledCompletedDate" _
& ", vClients.IntakeAssessorStaffID" _
& ", Staff_3.FirstName + ' ' + Staff_3.LastName AS IntakeAssessorStaffName" _
& ", vClients.IntakeAssessorAssignedDate" _
& ", vClients.IntakeAssessorCompletedDate" _
& ", vClients.IntakeReviewerStaffID" _
& ", Staff_4.FirstName + ' ' + Staff_4.LastName AS IntakeReviewerStaffName" _
& ", vClients.IntakeReviewerAssignedDate" _
& ", vClients.IntakeReviewerCompletedDate" _
& ", vClients.IntakeServicesStaffID" _
& ", Staff_5.FirstName + ' ' + Staff_5.LastName AS IntakeServicesStaffName" _
& ", vClients.IntakeServicesAssignedDate" _
& ", vClients.IntakeServicesCompletedDate" _
& ", vClients.Intake1stContactAssignedDays" _
& ", vClients.Intake1stContactCompletedDays" _
& ", vClients.Intake1stScheduledAssignedDays" _
& ", vClients.Intake1stScheduledCompletedDays" _
& ", vClients.IntakeAssessorAssignedDays" _
& ", vClients.IntakeAssessorCompletedDays" _
& ", vClients.IntakeReviewerAssignedDays" _
& ", vClients.IntakeReviewerCompletedDays" _
& ", vClients.IntakeServicesAssignedDays" _
& ", IntakeServicesCompletedDays" _
& ", Staff_6.FirstName + ' ' + Staff_6.LastName AS Intake1stSessionStaffName" _
& ", vClients.Intake1stSessionDate" _
& ", vClients.Intake1stSessionDays" _
& ", vClientServices.PurposeCodeID" _
& ", vClientServices.PurposeType" _
& ", vClientServices.PurposeCode" _
& ", vClientServices.PurposeDescription" _
& ", vClients.Status" _
& " FROM vClients" _
& " LEFT OUTER JOIN dbo.Staff ON vClients.Intake1stContactStaffID = Staff.StaffID " _
& " LEFT OUTER JOIN dbo.vClientServices ON vClientServices.ClientID = vClients.ClientID " _
& " LEFT OUTER JOIN dbo.ReferralSources ON vClients.ReferralSourceID = ReferralSources.ReferralSourceID" _
& " LEFT OUTER JOIN dbo.Staff AS Staff_1 ON Staff_1.StaffID = vClients.DataEntryStaffID " _
& " LEFT OUTER JOIN dbo.Staff AS Staff_2 ON Staff_2.StaffID = vClients.Intake1stScheduledStaffID" _
& " LEFT OUTER JOIN dbo.Staff AS Staff_3 ON Staff_3.StaffID = vClients.IntakeAssessorStaffID " _
& " LEFT OUTER JOIN dbo.Staff AS Staff_4 ON Staff_4.StaffID = vClients.IntakeReviewerStaffID " _
& " LEFT OUTER JOIN dbo.Staff AS Staff_5 ON Staff_5.StaffID = vClients.IntakeServicesStaffID " _
& " LEFT OUTER JOIN dbo.Staff AS Staff_6 ON Staff_6.StaffID = vClients.Intake1stSessionStaffID " _
& rsClients__sqlFrom _
& " WHERE " & rsClients__sqlFilter _
& " ORDER BY " & rsClients__sqlSortBy & ""
rsClients.CursorType = 0
rsClients.CursorLocation = 2
rsClients.LockType = 1
rsClients.Open()
rsClients_numRows = 0
%>
<% If Not rsClients.EOF And Not rsClients.BOF Then %>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsClients.EOF))
%>
<tr class="gridItem">
<td align="center" nowrap="nowrap"><img src='/images/details16x16.gif' border='0' title='Client Details' /></td>
<td nowrap="nowrap"><%=rsClients.Fields.Item("FirstName").Value & " " & rsClients.Fields.Item("LastName").Value%></td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("Status").Value)%></td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("OfficeName").Value)%></td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("ClientTeamName").Value)%></td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("PurposeType").Value & " - " & rsClients.Fields.Item("PurposeDescription").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("EnrolledDate").Value)%></td>
<td><%=(rsClients.Fields.Item("ReferralType").Value)%></td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("ReferralSource").Value)%></td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("ReferralSourceText").Value)%></td>
<td><%=(rsClients.Fields.Item("ReferralStaffName").Value)%></td>
<td align="center" bgcolor="#CCCCCC"> </td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("DataEntryStaffName").Value)%></td>
<td><% If Not IsNull(rsClients.Fields.Item("DataEntryDate").Value) Then Response.Write(FormatDateTime(rsClients.Fields.Item("DataEntryDate").Value,vbShortDate)) End If %></td>
<td align="center"><%=(rsClients.Fields.Item("DataEntryDays").Value)%></td>
<td align="center" bgcolor="#CCCCCC"> </td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("Intake1stContactStaffName").Value)%></td>
<td><%=(rsClients.Fields.Item("Intake1stContactAssignedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("Intake1stContactAssignedDays").Value)%></td>
<td><%=(rsClients.Fields.Item("Intake1stContactCompletedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("Intake1stContactCompletedDays").Value)%></td>
<td align="center" bgcolor="#CCCCCC"> </td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("Intake1stScheduledStaffName").Value)%></td>
<td><%=(rsClients.Fields.Item("Intake1stScheduledAssignedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("Intake1stScheduledAssignedDays").Value)%></td>
<td><%=(rsClients.Fields.Item("Intake1stScheduledCompletedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("Intake1stScheduledCompletedDays").Value)%></td>
<td align="center" bgcolor="#CCCCCC"> </td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("IntakeAssessorStaffName").Value)%></td>
<td><%=(rsClients.Fields.Item("IntakeAssessorAssignedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("IntakeAssessorAssignedDays").Value)%></td>
<td><%=(rsClients.Fields.Item("IntakeAssessorCompletedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("IntakeAssessorCompletedDays").Value)%></td>
<td align="center" bgcolor="#CCCCCC"> </td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("IntakeReviewerStaffName").Value)%></td>
<td><%=(rsClients.Fields.Item("IntakeReviewerAssignedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("IntakeReviewerAssignedDays").Value)%></td>
<td><%=(rsClients.Fields.Item("IntakeReviewerCompletedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("IntakeReviewerCompletedDays").Value)%></td>
<td align="center" bgcolor="#CCCCCC"> </td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("IntakeServicesStaffName").Value)%></td>
<td><%=(rsClients.Fields.Item("IntakeServicesAssignedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("IntakeServicesAssignedDays").Value)%></td>
<td><%=(rsClients.Fields.Item("IntakeServicesCompletedDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("IntakeServicesCompletedDays").Value)%></td>
<td align="center" bgcolor="#CCCCCC"> </td>
<td nowrap="nowrap"><%=(rsClients.Fields.Item("Intake1stSessionStaffName").Value)%></td>
<td><%=(rsClients.Fields.Item("Intake1stSessionDate").Value)%></td>
<td align="center"><%=(rsClients.Fields.Item("Intake1stSessionDays").Value)%></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsClients.MoveNext()
Wend
%>
You'll need to set a hold variable(s) for the column(s) you want to hinge on. Here would be some pseudo code that should get you down the right path:
strClientIdHold = ""
While NumRows <> 0 And Not EOF
If strClientIdHold <> rs("ClientId") Then
<td>rs("ClientId")</td>
<td>second column</td>
<td>third column</td>
<td>rs("Services")</td>
<td>fifth column</td>
<td>...</td>
strClientId = rs("ClientId")
Else
<td colspan="3"></td>
<td>rs("Services")</td>
<td colspan="8"></td>
End If
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsClients.MoveNext()
Wend
If you wanted you could do other checks too to see if other columns change... i.e. Can one client Id have more than one office or team that you'll want to pivot on and show that column too? You would then just have another hold variable for that as well.
I hope this helps.
Related
I've a screen with a list of components. When I scroll down the screen, go to the next screen from a button (lets say 20th component) and go back to the previous screen with back btn, the previous screen (with list of components) displays with the first component there. How can I show the screen with 20th component when backed?
Look at the video here
Container mainContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
mainContainer.setScrollableY(true);
for (Map<String, Object> entrySet : protectedPlantsList) {
String title = entrySet.get("title").toString();
String sname = entrySet.get("sname").toString();
String nname = entrySet.get("nname").toString();
Label plantSpeciesLabel = new Label(title);
TextArea family = new TextArea(sname);
TextArea nepaliName = new TextArea(nname);
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Button infoIcon1 = new Button("", "TextField");
infoIcon1.addActionListener(e -> {
new ThreatCategory(res, threatData1.getName(), infoIcon1.getName(), threatList).show();
});
mainContainer.add(BorderLayout.centerEastWest(plantSpeciesLabel, ...., .....));
}
Update 1:
ProtectedPlantAndSpecies class:
Container mainContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
mainContainer.setScrollableY(true);
for (Map<String, Object> entrySet : protectedPlantsList) {
String title = entrySet.get("title").toString();
String sname = entrySet.get("sname").toString();
String nname = entrySet.get("nname").toString();
Label plantSpeciesLabel = new Label(title);
TextArea family = new TextArea(sname);
TextArea nepaliName = new TextArea(nname);
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Button infoIcon1 = new Button("", "TextField");
infoIcon1.addActionListener(e -> {
Form myDestinationForm = new ThreatCategory(res, cat, cat_description, threatList);
myDestinationForm.addShowListener(f -> infoIcon1.requestFocus());
myDestinationForm.show();
});
mainContainer.add(BorderLayout.centerEastWest(plantSpeciesLabel, ...., .....));
}
ThreatCategory class:
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
Command backCommand = new Command("Back", backFontImage) {
#Override
public void actionPerformed(ActionEvent evt) {
new ProtectedPlantAndSpecies(res, true).show();
}
};
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
Do something like this:
Form hi = new Form("Last", BoxLayout.y());
Button t = new Button("Next");
hi.add(t);
t.addActionListener(e -> {
Form f = new Form("Showing Last", BoxLayout.y());
for(int iter = 0 ; iter < 20 ; iter++) {
f.add(new Button("Button " + iter));
}
Button last = new Button("Last");
f.add(last);
f.addShowListener(ee -> last.requestFocus());
f.show();
});
I have two pickers. The 2nd picker should be active as soon as the 1st picker is selected. But If the 2nd picker is clicked at first, the empty picker string is opened and then dialog stating choose the 1st picker is shown. How can I not show the empty picker string list if the first picker is not selected ?
Picker datePicker = new Picker();
datePicker.addActionListener(e -> {
SimpleDateFormat sf = new SimpleDateFormat("y");
String a = sf.format(datePicker.getDate());
SimpleDateFormat sf1 = new SimpleDateFormat("M");
String b = sf1.format(datePicker.getDate());
SimpleDateFormat sf2 = new SimpleDateFormat("d");
String c = sf2.format(datePicker.getDate());
getStartDate = a + "-" + b + "-" + c;
});
stationPicker.addActionListener(e -> {
if (!getStartDate.equals("")) {
_ _ _ _ _ _ _ _ _ ___ _
_ _ _ _ _ _ _ _ _ ___ _
}else{
Dialog.show("Warning", "Please choose the date first", "ok", null);
stationPicker.setSelectedString("Select the service center");
}
});
Have a look at the video so that the issue is more clear.
https://www.youtube.com/watch?v=Fmg13qm08Is
I was trying to get the values of radio button in html page when checked and insert it into the sqlite database and mysql. This is my full code below:
Form hi = new Form("Hi World");
final WebBrowser b = new WebBrowser(){
#Override
public void onLoad(String url) {
// Placed on onLoad because we need to wait for page
// to load to interact with it.
BrowserComponent c = (BrowserComponent)this.getInternal();
// Create a Javascript context for this BrowserComponent
JavascriptContext ctx = new JavascriptContext(c);
JSObject window = (JSObject)ctx.get("window");
window.set("addAsync", new JSFunction(){
public void apply(JSObject self, final Object[] args) {
String a = (String)args[0];
// Double b = (Double)args[1];
System.out.println("Value picked is "+a);
JSObject callback = (JSObject)args[1];
callback.call(new Object[]{new String(a)});
System.out.println("ok Good");
}
});
}
};
b.setPage( "<html lang=\"en\">\n" +
" <head>\n" +
" <meta charset=\"utf-8\">\n" +
" <script>\n" +
"function test() {"+
" var radios = document.getElementsByName('radiotest');"+
" var found = 1;"+
" for (var i = 0; i < radios.length; i++) { " +
" if (radios[i].checked) {"+
// " document.getElementById('input3').setAttribute('value', radios[i].value); " +
" alert(radios[i].value);"+
" found = 0;"+
" break;"+
" }"+
"}"+
" if(found == 1)"+
" {"+
" alert('Please Select Radio');"+
" } "+
"}"+
// + \n" +
" var radios = document.getElementsByName('radiotest')"+
" document.addEventListener('click', function(){\n" +
" var found = 1;"+
" for (var i = 0; i < radios.length; i++) { " +
" if (radios[i].checked) {"+
// " document.getElementById('input3').setAttribute('value', radios[i].value); " +
" alert(radios[i].value);"+
" found = 0;"+
" break;"+
" }"+
"}"+
" if(found == 1)"+
" {"+
" alert('Please Select Radio');"+
" } "+
" a = document.getElementById('val1').value ;\n" +
" b = document.getElementById('val2').value\n" +
" window.addAsync(a, b, function(result){\n" +
" document.getElementById('result').innerHTML = result;\n" +
" });\n" +
" }, true); "
+ "" +
" </script>\n" +
" </head>\n" +
" <body >\n" +
" <table border='0' cellspacing = '15'>"+
" <thead>"+
" </thead>"+
" <tbody>"+
" <tr>"+
" <td><font size = '3'> <b>A </font></b><input type='radio' name='radiotest' id='val1' onclick='test()' value='1' style='border: none;'> value1</input>"+
"</td>"+
" </tr>"+
" <tr>"+
" <td><font size = '3'> <b> B</font></b><input type='radio' name='radiotest' id='val2' onclick='test()' value='2' style='border: none;'> value2</input>"+
"</td>"+ " </tr>"+
" <tr>"+
" <td> <font size = '3'> <b>C </font></b><input type='radio' name='radiotest' id='val3' onclick='test()' value='3'style='border: none;'> value3</input>"+
" </tr>"+
"<tr>"+
" <td> <font size = '3'> <b>D </font></b> <input type='radio' name='radiotest'id='val4' onclick='test()' value='4'style='border: none;'> value4</input>"+
" </tr>"+
"</tbody>"+
"</table>"+
"<span id=\"result\"></span>"+
" </body>\n" +
"</html>", null);
hi.setLayout(new BorderLayout());
hi.setLayout(new BorderLayout());
hi.addComponent(BorderLayout.CENTER, b);
hi.show();
The code above did not work for me. Pls help.
The problem am having now is to add actionListener to the radio button when checked by collecting its value and insert these values into the database accordingly.
I have edited my code, With this I can get the value selected with javascript function with the code below. Now, How can I insert the values of the radio button into the database as I click on radio button.
Form hi = new Form("BrowserComponent", new BorderLayout());
BrowserComponent bc = new BrowserComponent();
bc.setPage( "<html lang=\"en\">\n" +
" <head>\n" +
" <meta charset=\"utf-8\">\n" +
" </head>\n" +
" <body >\n" +
" <table border='0' cellspacing = '15'>"+
" <thead>"+
" </thead>"+
" <tbody>"+
" <tr>"+
" <td><font size = '3'> <b>A </font></b><input type='radio' name='radiotest' id = 'val1' onclick='test()' value='1' style='border: none;'> value1</input>"+
"</td>"+
" </tr>"+
" <tr>"+
" <td><font size = '3'> <b> B</font></b><input type='radio' name='radiotest'id = 'val2' onclick='test()' value='2' style='border: none;'> val2</input>"+
"</td>"+
" </tr>"+
" <tr>"+
" <td> <font size = '3'> <b>C </font></b><input type='radio' name='radiotest' onclick='test()' value='3'style='border: none;'> val3</input>"+
" </tr>"+
"<tr>"+
" <td> <font size = '3'> <b>D </font></b> <input type='radio' name='radiotest' onclick='test()' value='4'style='border: none;'> val4</input>"+
" </tr>"+
"</tbody>"+
"</table>"+
" <script type='text/javascript'>" +
//This javascript is perfect now.
"function test() {"+
" var radios = document.getElementsByName('radiotest');"+
" var found = 1;"+
" for (var i = 0; i < radios.length; i++) { " +
" if (radios[i].checked) {"+
// " document.getElementById('input3').setAttribute('value', radios[i].value); " +
// " instruction = document.getElementById('input3').value" +
// "'"+option_code2+"'"+
" alert(radios[i].value);"+
" found = 0;"+
" break;"+
" }"+
"}"+
" if(found == 1)"+
" {"+
" alert('Please Select Radio');"+
" } "+
"}"+
"</script>"+
" </body>\n" +
"</html>", null);
TextField tf = new TextField();
hi.add(BorderLayout.CENTER, bc).
add(BorderLayout.SOUTH, tf);
//bc.addWebEventListener("onLoad", (e) -> bc.execute("fnc('<p>Hello World</p>')"));
hi.show();
Make sure your libraries are up to date, if the JavaScript bridge works correctly for setURL but fails for setPage it sounds like something we fixed in a recent update.
Getting data from various text boxes on a form and doing an update to a SQL Server database. Here is the creation of the SQL:
Dim upDateStr As String
upDateStr = "UPDATE dbo_Master_Accounts SET dbo_Master_Accounts.FirstName = " & Chr$(34) & Me.disFirstName & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.LastName = " & Chr$(34) & Me.disLastName & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Address_Line_1 = " & Chr$(34) & Me.disAddr1 & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.City = " & Chr$(34) & Me.disCity & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.State = " & Chr$(34) & Me.disState & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.PostalCode = " & Chr$(34) & Me.disPostalCode & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Phone_Number_1 = " & Chr$(34) & Me.disHomePhone & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Phone_Number_2 = " & Chr$(34) & Me.disCellPhone & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Gender = " & Chr$(34) & Me.disGender & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Date_Of_Birth = " & Chr$(34) & Me.disDateofBirth & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Email = " & Chr$(34) & Me.disEmailAddress & Chr$(34) & ", "
upDateStr = upDateStr + "WHERE (((dbo_Master_Accounts.Master_ID) = " & Chr$(34) & Me.frmoldCardno & Chr$(34) & ""
Looked at query in immediate and all the data is there and it looks correct. Here is the immediate window.
UPDATE dbo_Master_Accounts
SET dbo_Master_Accounts.FirstName = "John",
dbo_Master_Accounts.LastName = "Handy",
dbo_Master_Accounts.Address_Line_1 = "123 From",
dbo_Master_Accounts.City = "Somewhere",
dbo_Master_Accounts.State = "IL",
dbo_Master_Accounts.PostalCode = "50310",
dbo_Master_Accounts.Phone_Number_1 = "1234567890",
dbo_Master_Accounts.Phone_Number_2 = "",
dbo_Master_Accounts.Gender = "M",
dbo_Master_Accounts.Date_Of_Birth = "02/14/1967",
dbo_Master_Accounts.Email = "me#mine.com",
WHERE (((
dbo_Master_Accounts.Master_ID
) = "000055"
But I get a syntax error that I can't see. Tried running with only first and last two line of code and get the same error.
Thanks in advance
jpl
Start by trying this to see if it works (removed comma before where, and fixed the parenthesis) and then use parameters to do it right, because this way you're open to SQL injection attacks
Dim upDateStr As String
upDateStr = "UPDATE dbo_Master_Accounts SET dbo_Master_Accounts.FirstName = '" & Me.disFirstName & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.LastName = '" & Me.disLastName & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Address_Line_1 = '" & Me.disAddr1 & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.City = '" & Me.disCity & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.State = '" & Me.disState & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.PostalCode = '" & Me.disPostalCode & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Phone_Number_1 = '" & Me.disHomePhone & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Phone_Number_2 = '" & Me.disCellPhone & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Gender = '" & Me.disGender & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Date_Of_Birth = '" & Me.disDateofBirth & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Email = '" & Me.disEmailAddress & "' "
upDateStr = upDateStr + "WHERE (dbo_Master_Accounts.Master_ID) = '" & Me.frmoldCardno & "' "
I am trying to update the table which is working but after updating I cannnot see the updated data on the form when I ho to next record and comeback eventhough it gets updated on sql server.
Here is my code
Try
cn = Connection.connectionstringESLC()
cn.Open()
Dim query As String
query = "Update [School Admin Aug 2012] SET NAME='" & txtName.Text & _
"' , ADDRESS = '" & txtAddress.Text & _
"' , [Alternate Email] = '" & txtEmail.Text & _
"' , [ADVISOR NAME] = '" & txtAdvName.Text & _
"' , [DEPT NAME] = '" & txtDept.Text & _
"' , PROGRAM = '" & txtDegree.Text & _
"' , DEGREE = '" & txtMajor.Text & _
"', MAJOR = '" & txtProgram.Text & _
"', [DATE ADMITTED] = '" & dtpAdmitted.Value & _
"', [ADMISSION DECISION] = '" & cmbAdmDecision.Text & _
"' , [ENROLLMENT STATUS] = '" & cmbEnrollment.Text & _
"', [CAMPUS] = '" & cmbCampus.Text & _
"' , [ADVISING SHEET DATE] = '" & dtpAdvshtdt.Value & _
"' , [GRADUATION DATE] = '" & dtpGrdDt.Value & _
"' , [CURRENT POSITION] = '" & txtCurrentPosition.Text & _
"' , [GRE] = '" & txtGRE.Text & _
"' , [SLLA] = '" & txtSLLA.Text & _
"' , [KYPT] = '" & txtKYPT.Text & _
"' , [COMMENT] = '" & txtComment.Text & _
"' WHERE [MNUMBER] = '" & txtMNumber.Text & "'"
cmd = New SqlCommand(query, cn)
cmd.ExecuteNonQuery()
cn.Close()
cn = Nothing
MsgBox("Record updated successfully")
loadinfo()
Catch ex As Exception
MsgBox(ex.Message)
End Try
' I am also running loadinfo() code on page_load function
Public Sub loadinfo()
Try
cn = Connection.connectionstringESLC()
cn.Open()
cmd = New SqlCommand("Select * from [School Admin Aug 2012]")
cmd.Connection = cn
da.SelectCommand = cmd
da.Fill(ds, "dbo.School Admin Aug 2012")
da.Dispose()
cmd.Dispose()
If i < ds.Tables(0).Rows.Count - 1 Then
txtMNumber.Text = ds.Tables(0).Rows(i).Item(0)
txtName.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(1)), " ", ds.Tables(0).Rows(i).Item(1))
' IIf(IsDBNull(ds.Tables(0).Rows(0).Item(2)), " ", ds.Tables(0).Rows(0).Item(2))
txtAddress.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(2)), " ", ds.Tables(0).Rows(i).Item(2))
txtEmail.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(3)), " ", ds.Tables(0).Rows(i).Item(3))
txtAdvName.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(4)), " ", ds.Tables(0).Rows(i).Item(4))
txtDept.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(5)), " ", ds.Tables(0).Rows(i).Item(5))
txtProgram.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(6)), " ", ds.Tables(0).Rows(i).Item("PROGRAM"))
txtDegree.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(7)), " ", ds.Tables(0).Rows(i).Item("DEGREE"))
txtMajor.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(8)), " ", ds.Tables(0).Rows(i).Item("MAJOR"))
dtpAdmitted.Value = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(9)), "12/31/9998", ds.Tables(0).Rows(i).Item(9))
cmbAdmDecision.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(10)), " ", ds.Tables(0).Rows(i).Item(10))
cmbEnrollment.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(11)), " ", ds.Tables(0).Rows(i).Item(11))
cmbCampus.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(12)), " ", ds.Tables(0).Rows(i).Item(12))
dtpAdvshtdt.Value = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(13)), "12/31/9998", ds.Tables(0).Rows(i).Item(13))
dtpGrdDt.Value = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(14)), "12/31/9998", ds.Tables(0).Rows(i).Item(14))
txtCurrentPosition.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(15)), " ", ds.Tables(0).Rows(i).Item(15))
txtGRE.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(16)), " ", ds.Tables(0).Rows(i).Item(16))
txtSLLA.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(17)), " ", ds.Tables(0).Rows(i).Item(17))
txtKYPT.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(18)), " ", ds.Tables(0).Rows(i).Item(18))
txtComment.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(19)), " ", ds.Tables(0).Rows(i).Item(19))
cn.Close()
cn = Nothing
ElseIf i < 0 Then
i = 0
Else
MsgBox("This is the last record")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub