get a array of values from the url in asp.net - asp.net

I am using ASP.NET for the first time.
Here is my issue.
I have a ASP.NET page.
some other website redirects to my webpage and the url is
http://localhost/mysite/newpage.aspx?request=424718&to%5B0%5D=111832&to%5B1%5D=1186313&to%5B2%5D=100009#_=_
actually what that website send is a request value and an array of id 's
I have to get those values in my page and display them.
I have used #Request["request"] to get the request value.
But I do not know how to get the id values (since it is an array). I tried #Request["to"] and it gives null.
I also cannot understand that url encoding.. it is supposed to be like this
?request=3435&to=3495&to=435&to=3546

The ids & values that you are looking for, I believe, are in the URL. This is called the querystring.
Single Values
This code will output each key-value-pair from the querystring. If there are multiple values, they will be comma-delimited.
C#
foreach (String key in Request.QueryString.AllKeys)
{
Response.Write("Key: " + key + " Value: " + Request.QueryString[key]);
}
VB.NET
For Each key as String in Request.QueryString.Allkeys
Response.Write("Key: " & key & " Value: " & Request.QueryString(key))
Next
If you use the above code, you will notice that there is a comma-delimited list of values outputted for the to key. This is because the to key is used multiple times.
Multiple Values
This will output each key followed by each key's values.
foreach (String key in Request.QueryString.AllKeys)
{
var values = Request.QueryString.GetValues(key);
foreach (String item in values)
{
Response.Write("value: " + item + " ";
}
}
This will output each key and then each value for each key, even if there are multiple.
Reference
Is there a way to get all the querystring name/value pairs into a collection?

Related

Python requests.get does not take field names for data

I need to generate data using the below url via requests.get :
fields = ("")
response_2 = requests.get(BASEURL + 'services/v17.0/report-jobs/' + jobId + "?fields=" +fields ,
headers = header_param)
For the purpose of the question, both the BASEURL and the JobID are pre defined.
However, there are several field names in the dataset such as Date, [Agent Name], [Agent ID] etc. that I'm looking to generate.
When I leave the fields object blank, no data is generated.
When I try to define the fields object using
fields = ("Date, Agent Name")
or
fields = ("Date", "Agent Name")
I always get back the error : Invalid fields argument
What is the best way to fix this?
I'm not sure what result you want, but the problem is you're trying to concatenate a string and a tuple, and misusing a tuple.
requests.get(BASEURL + 'services/v17.0/report-jobs/' + jobId + "?fields=".join(str(i) for i in fields)

can anyone tell me what's wrong in this?

public void deleteData(String name,int itemID){
SQLiteDatabase db=getWritableDatabase();
String query="DELETE FROM "+ TABLE_NAME + " WHERE "+ "'"+ COL1 +"'"+ " = "+ itemID + " AND "+ "'" + COL2 + "'" +" ="+ " '"+ name + "'";
db.execSQL(query);
db.execSQL(query);
}
The following are wrong or could be considered as wrong.
There should be no need to call the exact same query twice.
It is considered better to use the Android SDK's convenience methods when they suit (instead of using the execSQL method the delete method is more appropriate).
There is the potential for SQLinjection attacks when parameters are used directly in strings that are executed directly as SQL (note resolving 2 and using the appropriate parameters resolves this issue).
There is, unless the columns are named with invalid names, no need to enclose column names in single quotes or alternative characters (invalid names can make life difficult so if used they would be considered wrong by many).
If the delete (the first one), is not working or if the delete appears to not return an appropriate result after using pragma count_changes that could be due to the row not existing (did the row get inserted?) or that the 2nd query which would delete nothing is hiding the result of the first query.
pragma count_changes is deprecated in later version of SQLite so should no longer be used (albeit that Android's SQlite version is typically some way behind).
As a fix to all bar the id not existing you could use the following :-
public int deleteData(String name,int itemID){
SQLiteDatabase db=getWritableDatabase();
String whereclause = COL1 + "=? AND " + COL2 + "=?";
String[] whereargs = new String[]{String.valueOf(int),name};
return db.delete(TABLE_NAME,whereclause,whereargs);
}
Note that the methods signature results in an int being returned, this will be the number of rows deleted.

Alternative for recursive expressions in DataColumn

In my DataSet (which is persisted as XML), I have an Area table with three columns: ID, Name, and ParentId. ParentId is a foreign key that refers back to ID, effectively creating a hierarchy of Areas.
I want to maintain the full path of each Area in a new column called Path, whose value can be defined recursively as
{ area.Name ; if ParentId is null
area.Path := {
{ Parent.Path + "\" + area.Name ; otherwise
I would have liked to implement this column as a computed column.
Unfortunately, when I try to set the Expression property to the following expression
iif(isnull(ParentId, 0) = 0, Name, Parent.Path + '\' + Name)
I get the following error:
Cannot set Expression property due to circular reference in the expression.
This seems to rule out a computed column. So what are the alternatives? I.e. how can I make sure that the Path column always contain a correct value that can be used in a data-bound UI?
Attach an event handler to the datatable's row adding/changing (use events ending in ING as these fire before) events and check the value being added/altered has a closed path

SQLite query to find primary keys

In SQLite I can run the following query to get a list of columns in a table:
PRAGMA table_info(myTable)
This gives me the columns but no information about what the primary keys may be. Additionally, I can run the following two queries for finding indexes and foreign keys:
PRAGMA index_list(myTable)
PRAGMA foreign_key_list(myTable)
But I cannot seem to figure out how to view the primary keys. Does anyone know how I can go about doing this?
Note: I also know that I can do:
select * from sqlite_master where type = 'table' and name ='myTable';
And it will give the the create table statement which shows the primary keys. But I am looking for a way to do this without parsing the create statement.
The table_info DOES give you a column named pk (last one) indicating if it is a primary key (if so the index of it in the key) or not (zero).
To clarify, from the documentation:
The "pk" column in the result set is zero for columns that are not
part of the primary key, and is the index of the column in the primary
key for columns that are part of the primary key.
Hopefully this helps someone:
After some research and pain the command that worked for me to find the primary key column name was:
SELECT l.name FROM pragma_table_info("Table_Name") as l WHERE l.pk = 1;
For the ones trying to retrieve a pk name in android, and while using the ROOM library.
#Oogway101's answer was throwing an error: "no such column [your_table_name] ... etc.. etc...
my way of query submition was:
String pkSearch = "SELECT l.name FROM pragma_table_info(" + tableName + ") as l WHERE l.pk = 1;";
database.query(new SimpleSQLiteQuery(pkSearch)
I tried using the (") quotations and still error.
String pkSearch = "SELECT l.name FROM pragma_table_info(\"" + tableName + "\") as l WHERE l.pk = 1;";
So my solution was this:
String pragmaInfo = "PRAGMA table_info(" + tableName + ");";
Cursor c = database.query(new SimpleSQLiteQuery(pragmaInfo));
String id = null;
c.moveToFirst();
do {
if (c.getInt(5) == 1) {
id = c.getString(1);
}
} while (c.moveToNext() && id == null);
Log.println(Log.ASSERT, TAG, "AbstractDao: pk is: " + id);
The explanation is that:
A) PRAGMA table_info returns a cursor with various indices, the response is atleast of length 6... didnt check more...
B) index 1 has the column name.
C) index 5 has the "pk" value, either 0 if it is not a primary key, or 1 if its a pk.
You can define more than one pk so this will not bring an accurate result if your table has more than one (IMHO more than one is bad design and balloons the complexity of the database beyond human comprehension).
So how will this fit into the #Dao? (you may ask...)
When making the Dao "abstract" you have access to a default constructor which has the database in it:
from the docummentation:
An abstract #Dao class can optionally have a constructor that takes a Database as its only parameter.
this is the constructor that will grant you access to the query.
There is a catch though...
You may use the Dao during a database creation with the .addCallback() method:
instance = Room.databaseBuilder(context.getApplicationContext(),
AppDatabase2.class, "database")
.addCallback(
//You may use the Daos here.
)
.build();
If you run a query in the constructor of the Dao, the database will enter a feedback loop of infinite instantiation.
This means that the query MUST be used LAZILY (just at the moment the user needs something), and because the value will never change, it can be stored. and never re-queried.

How to insert multiple asp.net checkboxes values to MSSQl database as comma seperaed string 1,2,3,4,5 using vb.net?

How to insert and retrive multiple asp.net checkboxes values to MSSQl database as comma seperaed string 1,2,3,4,5 using vb.net ?
and retrieve the inserted checkbox chekched in disabled form ..using vb.net
example of this is :
http://www.redbus.in/Booking/SeatSelection.aspx?rt=4017230&doj=31-Dec-2010&dep=04:55%20PM&showSpInst=false
I want this type of whole layout in vb.net ... means if user registered selected seats then then next the same page load for todays date the selected seats will be disabled ...
pleas provide me the code snippet for that // insert and retrieve funda... in checkbox
Try with such a loop
string str = "";
for (int i = 0; i <= 29; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
string b = CheckBoxList1.Items[i].Value;
str += b + " , ";
}
}
than make an insert statement and you are putting all the checkbox values into a column.
than just call select statement call the column
You are doing a very bad thing storing lists of values in a single MSSQL column. I know it may be convenient now, but it is always eventually bad news. Why not store booked seats in their own table, one seat per row? When you store a list of values in a column, you restrict access to the information stored in that column to only the code that can split the list. It isn't available to database queries or to other code as a list, merely as a string. You will end up replicating the code to split this string to other places that need the list data.

Resources