I am getting error at line no 34. I have also a table in database with column post
Line 32: Label5.Text = ds.Tables[0].Rows[0]["date_of_birth"].ToString();
Line 33:
Line 34: Label8.Text = ds.Tables[0].Rows[0]["post"].ToString();
Line 35: Label7.Text = ds.Tables[0].Rows[0]["subjects"].ToString();
Line 36: Label6.Text = ds.Tables[0].Rows[0]["Score"].ToString();
**strong text**
There's a 90% chance that you just got the capitalization wrong.
Check if your column is actually named Post and try this code:
Line 34: Label8.Text = ds.Tables[0].Rows[0]["Post"].ToString();
To avoid an exception for tables that may or may not contain this column, you can check for the presence of this column dynamically:
if(ds.Tables[0].Columns.Contains("post"))
//do something
Related
i have a file with multiple lines like this:
Port id: 20
Port Discription: 20
System Name: cisco-sw-1st
System Description:
Cisco 3750cx Switch
i want to get the next line, if the match found in the previous line, how would i do that.
with open("system_detail.txt") as fh:
show_lldp = fh.readlines()
data_lldp = {}
for line in show_lldp:
if line.startswith("System Name: "):
fields = line.strip().split(": ")
data_lldp[fields[0]] = fields[1]
elif line.startswith("Port id: "):
fields = line.strip().split(": ")
data_lldp[fields[0]] = fields[1]
elif line.startswith("System Description:\n"):
# here i Want to get the next line and append it to the dictionary as a value and assign a
# key to it
pass
print()
print(data_lldp)
Iterate each line in text and then use next when match found
Ex:
data_lldp = {}
with open("system_detail.txt") as fh:
for line in fh: #Iterate each line
if line.startswith("System Name: "):
fields = line.strip().split(": ")
data_lldp[fields[0]] = fields[1]
elif line.startswith("Port id: "):
fields = line.strip().split(": ")
data_lldp[fields[0]] = fields[1]
elif line.startswith("System Description:\n"):
data_lldp['Description'] = next(fh) #Use next() to get next line
print()
print(data_lldp)
Check out this question about getting the next value(in your case the next line) in a loop.
Python - Previous and next values inside a loop
While executing the following code i'm getting below error, Just for information matchObj here returns a tuple value ..
$ ./ftpParser3_re_dup.py
Traceback (most recent call last):
File "./ftpParser3_re_dup.py", line 13, in <module>
print("{0:<30}{1:<20}{2:<50}{3:<15}".format("FTP ACCOUNT","Account Type","Term Flag"))
IndexError: tuple index out of range
Code is below:
from __future__ import print_function
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE,SIG_DFL)
import re
with open('all_adta', 'r') as f:
for line in f:
line = line.strip()
data = f.read()
# Making description & termflag optional in the regex pattern as it's missing in the "data_test" file with several occurrences.
regex = (r"dn:(.*?)\nftpuser: (.*)\n(?:description:* (.*))?\n(?:termflag:* (.*))")
matchObj = re.findall(regex, data)
print("{0:<30}{1:<20}{2:<50}{3:<15}".format("FTP ACCOUNT","Account Type","Term Flag"))
print("{0:<30}{1:<20}{2:<50}{3:<15}".format("-----------","------------","--------"))
for index in matchObj:
index_str = ' '.join(index)
new_str = re.sub(r'[=,]', ' ', index_str)
new_str = new_str.split()
# In below print statement we are using "index[2]" as index is tuple here, this is because
# findall() returns the matches as a list, However with groups, it returns it as a list of tuples.
print("{0:<30}{1:<20}{2:<50}{3:<15}".format(new_str[1],new_str[8],index[2],index[3]))
In the line print("{0:<30}{1:<20}{2:<50}{3:<15}".format("FTP ACCOUNT","Account Type","Term Flag")) you have mentioned 4 indices but given only 3 i.e. "FTP ACCOUNT","Account Type","Term Flag"
Remove the 4th index or add a new one
I would like to read a block of data entered from the user interactively in the Python command prompt in Windows. The data is entered all at once i.e. in one shot. Data that I want to read and parse is given below. I would like to read each line, parse it and display the output as Timezone, Time, Date
TOD Output: 2018-02-22 13:37:27 PST
TOD Output: 2018-02-22 13:37:28 PST
TOD Output: 2018-02-22 13:37:29 PST
TOD Output: 2018-02-22 13:37:30 PST
TOD Output: 2018-02-22 13:37:31 PST
TOD Output: 2018-02-22 13:37:32 PST
The code that I have written so far is below:
import sys
sys.stdin = input("Enter the GNSS message")
for line in sys.stdin.readlines():
GNSS_data = line.split(" ")
print("Timezone: {}".format(GNSS_data[-1]))
print("Time: {}".format(GNSS_data[-2]))
print("Date = {}".format(GNSS_data[-3]))
print("\n")
I then get the following error
Traceback (most recent call last):
File "C:/Users/Tareq-Laptop/AppData/Local/Programs/Python/Python36/Scripts/Decipher.py", line 4, in
for line in sys.stdin.readlines():
AttributeError: 'str' object has no attribute 'readlines'
I think I am very close to the answer but making a syntax mistake somewhere. Please tell me what is it that I am doing incorrectly.
Are there any other simple methods of accomplishing my task.
This works for me.
while True:
line = input('Enter the GNSS message')
print(line)
if line == 'done':
break
GNSS_data = line.split(" ")
print("Timezone: {}".format(GNSS_data[-1]))
print("Time: {}".format(GNSS_data[-2]))
print("Date = {}".format(GNSS_data[-3]))
print("\n")
I'm using SQLite on Windows UWP (10).
This is what I am doing:
Open connection
Begin Transaction
Update row
Commit Transaction
Close connection
And yet, the value in the database is not actually written to the table. When I reload the record (after disconnecting and reconnecting, or not disconnecting) the value remains from before I called the update.
Is there something extra I need to do? In DB Browser for SQLite, there is a menu item called "Write Changes". What does that do? Just a normal commit? In the browser, the changes are only committed if I click on this menu item.
Also, I put a trace on the connection, and this is what came up:
Executing: begin transaction
Executing: UPDATE
'TaskManagement.TaskInfo'
SET
StatusKey = #StatusKey, ProbAddDttm = #ProbAddDttm, ProbCode = #ProbCode, ProbPriority = #ProbPriority, ProbGroup = #ProbGroup, ProbInsp = #ProbInsp, Activity = #Activity, UpdateDttm = #UpdateDttm, Asset = #Asset, Address = #Address, TaskStartDttm = #TaskStartDttm, MaintenanceScheduleSetup = #MaintenanceScheduleSetup, MaintenanceScheduleBatch = #MaintenanceScheduleBatch, ProbZone = #ProbZone, ProbContractor = #ProbContractor, ProbNotes = #ProbNotes, JobCompleted = #JobCompleted, Resolution = #Resolution, Result = #Result, ActType = #ActType, Complaint = #Complaint, BudgetNo = #BudgetNo, Contractor = #Contractor, MapLocCorrect = #MapLocCorrect, FollowUpWorkRequired = #FollowUpWorkRequired, Condition = #Condition, ActPriority = #ActPriority, ExpectedVersion = #ExpectedVersion, EmailProbOriginator = #EmailProbOriginator, IsBug = #IsBug, IsCompletePendingCheckIn = #IsCompletePendingCheckIn
WHERE
TaskInfoKey = #PrimaryKey
0: 63711ec4-57d0-4a23-8595-0022b757af44
1: 6
2: 2013-06-03 08:56:39:117
3: 13
4: 2
5: 17
6: 24
7:
8: 2015-11-10 04:05:09:502
9:
10:
11: 2013-06-03 08:56:39:117
12:
13:
14:
15:
16: Test this mofo!
17: 2013-08-15 12:13:24:620
18:
19:
20:
21:
22:
23: 4
24: False
25: False
26:
27:
28: 3
29: False
30: False
31: False
Executing: Commit
So, in the end, the problem was that I was not passing the parameters in to the library correctly. The connection's CreateCommand method only allows you to pass in the command text, and an array of objects. This is incorrect because that means you can't name the parameters. So, I consider this a piece of missing functionality in this particular implementation of SQLite for UWP.
Secondly, this should have errored! None of the parameter names I mentioned above were passed in to the command, and yet when I ran it, no exception was thrown. So, I consider this to be the second bug in the implementation.
I fixed it like this:
var command = _Connection.CreateCommand(commandText, new object[0]);
if (parameters != null)
{
foreach (var parameter in parameters)
{
if (parameter.ParameterValue is DateTime)
{
parameter.ParameterValue = ((DateTime)parameter.ParameterValue).ToString("yyyy-MM-dd hh:mm:ss:fff");
}
command.Bind(parameter.ParameterName, parameter.ParameterValue);
}
}
return command;
I am having a big procedure where in I'm doing a insert in a scenario.
Unfortunately, I am getting NOT DATA FOUND exception in the INSERT statement where in it don't have select clause for values.
INSERT INTO CW_PC_CT
(BATCH_ID, CONTRACT_TYPE, CONTRACT_CATEGORY, ELEMENT_ID, COMMITMENT_REFERENCE, DURATION_UNITS, DURATION,
PLAN_ID_DISCOUNT, PLAN_ID_CREDIT, ACTIVATION_TYPE_ID_NRC, TERMINATION_TYPE_ID_NRC, IS_PROMOTION,DESCRIPTION_CODE,
FOREIGN_CODE, START_BY_UNITS, START_BY, ACTIVE_DATE, FIXED_START_DATE, FIXED_END_DATE, PARTIAL_PERIOD,
COMMITMENT_TYPE_ID_NRC, DISCOUNT_BASE_PERIOD, ROLLOVER_ORDER, ROLLOVER_GROUPING,BONUS_POINT_ID, PRORATE_CONTRACT_START,
PRORATE_CONTRACT_END, PRORATE_INTERIM_BILL, PRORATE_PERIOD_CHANGE, PRORATE_ACCOUNT_START,
PRORATE_ACCOUNT_END, PRORATE_TARGET_THRESHOLD, PRORATE_TARGET_REBATES, ALLOW_ACCOUNT, ALLOW_SERV_INST,
ALLOW_ACCT_GROUP, ALLOW_SI_GROUP, BILL_PERIOD, MIN_DURATION_UNITS, MIN_DURATION, MIN_NOTICE_UNITS, MIN_NOTICE_DELAY,
IS_CUSTOM, WHEN_APPLIED, APPLY_DURING_SUSPEND)
VALUES(V_BATCH_ID, V_CONTRACT_TYPE, 8, V_GET_PARAM_INT('P_ELEMENT_ID_CT'),
V_GET_PARAM_INT('P_COMMIT_REF_CT'), V_GET_PARAM_INT('P_DURATION_UNITS_CT_DIS'), V_GET_PARAM_INT('P_DURATION_CT_DIS'),
V_GET_PARAM_INT('P_PLAN_ID_DISC_CT'), V_PLAN_ID_CREDIT, V_GET_PARAM_INT('P_ACT_TYPE_ID_NRC_CT_DIS'),
V_GET_PARAM_INT('P_TERM_TYPE_ID_NRC_CT'), V_GET_PARAM_INT('P_IS_PROMOTION_CT'), V_DESCRIPTION_CODE,
V_GET_PARAM_INT('P_FOREIGN_CODE_CT'), V_GET_PARAM_INT('P_START_BY_UNITS_CT'), V_GET_PARAM_INT('P_START_BY_CT'),
V_COMPONENT_ACTIVE_DATE, NULL, NULL, V_GET_PARAM_INT('P_PARTIAL_PERIOD_CT'),
V_GET_PARAM_INT('P_COMMIT_TYPE_ID_NRC_CT'), V_GET_PARAM_INT('P_DISC_BASE_PERIOD_CT'),
V_GET_PARAM_INT('P_ROLLOVER_ORDER_CT'), V_GET_PARAM_INT('P_ROLLOVER_GRP_CT'),
V_GET_PARAM_INT('P_BONUS_POINT_ID_CT'), V_GET_PARAM_INT('P_PRORATE_CONTRACT_START_CT'),
V_GET_PARAM_INT('P_PRORATE_CONTRACT_END_CT'), V_GET_PARAM_INT('P_PRORATE_INTERIM_BILL_CT'),
V_GET_PARAM_INT('P_PRORATE_PERIOD_CHANGE_CT'), V_GET_PARAM_INT('P_PRORATE_ACCOUNT_START_CT'),
V_GET_PARAM_INT('P_PRORATE_ACCOUNT_END_CT'), V_GET_PARAM_INT('P_PRORATE_TARGET_TRSHLD_CT'),
V_GET_PARAM_INT('P_PRORATE_TARGET_REBATES_CT'), V_GET_PARAM_INT('P_ALLOW_ACCOUNT_CT'),
V_GET_PARAM_INT('P_ALLOW_SERV_INST_CT'), V_GET_PARAM_INT('P_ALLOW_ACCT_GROUP_CT'),
V_GET_PARAM_INT('P_ALLOW_SI_GROUP_CT'), V_GET_PARAM_INT('P_BILL_PERIOD_CT'),
V_GET_PARAM_INT('P_MIN_DURATION_UNITS_CT'), V_GET_PARAM_INT('P_MIN_DURATION_CT'),
V_GET_PARAM_INT('P_MIN_NOTICE_UNITS_CT'), V_GET_PARAM_INT('P_MIN_NOTICE_DELAY_CT'),
V_GET_PARAM_INT('P_IS_CUSTOM_CT'), V_GET_PARAM_INT('P_WHEN_APPLIED_CT'), V_GET_PARAM_INT('P_APPLY_DURING_SUSPEND_CT'));
Below is the exception I am getting..
ORA-01403: no data found
ORA-06512: at "ABC.ABCDEFGHIJKL", line 2500
ORA-06512: at line 9
I am wondering the insert statement don't have select clause for getting data but no data found exception was coming.
can someone help with this.
Edit:
V_GET_PARAM_INT is not a procedure or function.
TYPE T_DEFAULT_INT IS TABLE OF CW_PC_CONFIG_DEFAULT_MASTER.INT_VALUE%TYPE
INDEX BY CW_PC_CONFIG_DEFAULT_MASTER.PARAMETER_NAME%TYPE;
V_GET_PARAM_INT T_DEFAULT_INT;
V_GET_PARAM_CHAR T_DEFAULT_CHAR;
FOR C_PARAM_INT IN C_LOAD_PC_DEFAULT_INT
LOOP
V_PARAMETER_NAME := C_PARAM_INT.PARAMETER_NAME;
V_PARAM_INT_VALUE := C_PARAM_INT.INT_VALUE;
V_GET_PARAM_INT(V_PARAMETER_NAME) := V_PARAM_INT_VALUE;
END LOOP;