I need some help with parsing information from a query string to a database.

There is a company that wants to send me information to a page on my server as a query string (http post)

e.g. www.mydomain.com/info.aspx?Name=Smith&LastName=Taylor

They will send probably about 15 different strings of information a day. I need to get this information and put it into my database automatically without user interaction.

I have been reading about http web request and so on but I cant understand how the server knows when a new piece of information has been submitted and how I get it to populate the database automatically.

What information would I need to add to the receiving page.

Recommended Answers

All 4 Replies

Let say if you have a query string as shown in the below code

http://www.xyz.com?id=123&uid=shiv

You can then get the values in the code as shown below

request.querystring["uid"]

The above value you can then insert using ADO.NET

Thank you for your reply. I appreciate it and it will help me.

But if the supplier is sending through 15 bits of information a day with different values, how would I check or know when they submit the data and automate the adding to the database.

Do I need to use webrequest or something? or add something to the page_load event

You you need read about Generic handlers. When you implement a generic handlers that means you're telling the ASP.NET engine to act in a certain way and do a certain thing whenever your application comes across a request of a generic type (image, querystring...). That is one way that I know of to automate the reading and inserting the querystring into the ur database.

Hope this helps mate!

P.S. should you need the book (Pro ASP.NET 3.5 in C# 3.0) mail me up at lazarevsky@hotmail.com and i'll send it to you in PDF.

khadakbist showed you how to do it. All you need to do is make a check to see if you have a query string. So lets say they are going to be using a name like "myString"

http://www.xyz.com?myString=This_is_the_Information

Do something like this.

string myCheck = request.querystring["myString"].ToString();

        if (!string.IsNullOrEmpty(myCheck))
        {
            //insert into database
        }

So now when ever your web page recieves a request that has a query string named myString it will look and see if it is null. If it is not null or empty it will add it to your database.

Myself I would setup a page just for this so the only trafic to that page will be this company that is sending you info in a query string. I also hope you trust them alot. I would also check that query for any type of scripts because if someone find that page and knows you are just adding the content of the query string to your database they could do some major damage to your site.

Edit: Forgot to also say that this is not a http post. When you are recieving info through a query string it is a (http get)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.