开发者

ASP.Net String Split not working

Here's my code

Dim RefsUpdate As String() = Session("Refs").Split("-"C)

Dim PaymentsPassedUpdate As String() = Session("PaymentsPassed").Split("-"C)

Dim x as Integer

For x = 1 to RefsUpdate.Length - 1

Dim LogData2 As sterm.markdata = New sterm.markdata() 

Dim queryUpdatePaymentFlags as String = ("UPDATE OPENQUERY (db,'SELECT * FROM table WHERE ref = ''"+ RefsUpdate(x) +"'' AND bookno = ''"+ Session("number") +"'' ') SET alpaid = '"+PaymentsPassedUpdate(x) +"', paidfl = 'Y', amountdue = '0' ") 

Dim drSetUpdatePaymentFlags As DataSet = Data.Blah(queryUpdatePaymentFlags) 

Next 

I don't get any errors for this but it doesn't seem to working as it should

I'm passing a bookingref like this AA123456 - BB123456 - CC123456 - etc and payment like this 50000 - 10000 - 30000 -

I basically need to update the db wit开发者_运维技巧h the ref AA123456 so the alpaid field has 50000 in it.

Can't seem to get it to work

Any ideas?

Thanks

Jamie


I'm not sure what isn't working, but I can tell you that you are not going to process the last entry in your arrays. You are going from 1 to Length - 1, which is one short of the last index. Therefore, unless your input strings end with "-", you will miss the last one.


Your indexing problem mentioned by Mark is only one item, but it will cause an issue. I'd say looking at the base your problem stems from not having trimmed the strings. Your data base probably doesn't have spaces leading or trailing your data so you'll need to do something like:

Dim refsUpdateString as string = RefsUpdate(x).Trim()
Dim paymentsPassedUpdateString as string = PaymentsPassedUpdate(x).Trim()

...

Dim queryUpdatePaymentFlags as String = ("UPDATE OPENQUERY (db,'SELECT * FROM table WHERE ref = ''" & refsUpdateString  & "'' AND bookno = ''" & Session("number") & "'' ') SET alpaid = '" & paymentsPassedUpdateString & "', paidfl = 'Y', amountdue = '0' ")  

Also, I would recommend keeping with the VB way of concatenation and use the & character to do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜