查询字符串拆分值 [英] query string split values

查看:109
本文介绍了查询字符串拆分值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询字符串是.... \ mypage.asp?q ="Name=Ram|Email=ram@yahoo.com|Mobile=123456789|Address=sdfsg"
在这里,我想将其拆分.例如-Name = Ram,Email = ram @ yahoo.com ...等,在这里,我想将此值插入到Name,Email ...等数据库字段中.字符串可能会有所不同.请告诉我
解决方案,这里我要在.asp页而不是.aspx页的pageload事件中插入值.


请给我插入代码,以获取sql服务器数据库中插入值.from .asp页.

my query string is....\mypage.asp?q="Name=Ram|Email=ram@yahoo.com|Mobile=123456789|Address=sdfsg"
here i want to split it.As like- Name=Ram,Email=ram@yahoo.com...etc,and here,I want to insert this values in database field like Name,Email...etc.Here also query string may be varied.Please tell me
solution ,here i want to insert values in pageload event of .asp page not .aspx page.


please give me insertion code for insert value in sql server database.from .asp page.

推荐答案

您可以使用 SqlCommand [^ ],定义 SqlParameters [
You can use String.Split[^] to split the input based on the delimiter. This will give a string array where you will find the idividual elements.

However, if the amount pf fields may vary in your input string, how are you going to know which field is which?

Anyhow, after you have splitted the string, you can build up a SqlCommand[^], define SqlParameters[^] and the use the ExecuteNonQuery method to insert the data into the database.

The insert statement would look something like:
INSERT INTO TableNamw (Name, Email, ...)
VALUES (@name, @email, ...)


其中@ ...将是您在其中定义要从字符串数组插入的值的参数.

要定义参数和值,可以使用
SqlParameterCollection.AddWithValue [ ^ ]方法


where @... will be the parameters where you define the values to insert from the string array.

To define the parameters and the values you can use SqlParameterCollection.AddWithValue[^] method


我不清楚,但我认为这对您有帮助

首先获取查询字符串值
然后使用string.split(''|'')
就像
string [] variable = yourquerystring.split(''|``);
i dont know exactly but i think it helps you

first get the query string value
then use string.split(''|'')
like
string [] variable=yourquerystring.split(''|'');


使用此.

use this.

"Inventory Reports/CRSalesInvoice.aspx?" + "&Name=" + "Ram" + "&Email=" + "ram@yahoo.com"



并在另一个表单上访问名称和电子邮件查询字符串,如下所示.



and access name and email query string on another form as follow.

string Name;
Name = Request.QueryString["Name"];
string Email;
Email = Request.QueryString["Email"];




Yogesh Pednekar.




Yogesh Pednekar.


这篇关于查询字符串拆分值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆