Visual Basic .NET Forums  

Go Back   Visual Basic .NET Forums > VB.NET > Winforms Data Access

Winforms Data Access VB.NET development for data access and back-end related areas

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-04-2008, 4:29 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Age: 45
Posts: 47
Reputation: 10
victor64 is on a distinguished programming path ahead
Default Help with Partial string Search

Hello,

I'm try to update data a column in the IDENTIFICATION_DATA based on partial match the AOP5 table. The problem is I don't know how to parse the string after 4 spaces and only consider 11 characters, for example the data in the identification table is in the following format: 00-028-1234. The data in the AOP5 table is in the following format 1305-00-028-1234(1). I only want to update insert data in the identification table when 00-028-1234 matches in both tables.

Thanks

Victor

Code:

Dim mySQL_Statement As String = "UPDATE IDENTIFICATION_DATA " & vbNewLine & _
" INNER JOIN " & vbNewLine & _
" aop5 " & vbNewLine & _
" ON IDENTIFICATION_DATA.NIIN " & _
" = aop5.NSN " & vbNewLine & _ ''''how do i modify this line to only search for data after the fifth position and the next 11 characters??
" SET IDENTIFICATION_DATA.NARC = " & _
" aop5.sn "

Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\aopt2002orgorg.mdb;Persist Security Info=True;Jet OLEDBatabase Password=testaopupdate"
Dim objConnection As New OleDb.OleDbConnection(ConnectionString)

'data adapter
Dim objDataAdapter As New OleDb.OleDbDataAdapter(mySQL_Statement, objConnection)

''dataset object
Dim objDataSet As New DataSet
' 'fill dataset
objConnection.Open()
objDataAdapter.Fill(objDataSet, "SN")
objConnection.Close()
MsgBox("Completed")
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-04-2008, 5:04 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 712
Reputation: 369
MattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalist
Default

Didn't I answer this one already?

Code:
SELECT *
FROM TableA a JOIN TableB b ON SUBSTRING(a.column, 5, 11) = b.column
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-04-2008, 5:37 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Age: 45
Posts: 47
Reputation: 10
victor64 is on a distinguished programming path ahead
Default

Hello,

I'm trying to update the value in tableA, therefore I need to use the insert and update command, I tried to modify my code using your syntax but it still doesn't work. In this case table A is identification table and table B is AOP5. The error message states the substring is not recognized.

Dim mySQL_Statement As String = "UPDATE IDENTIFICATION_DATA " & vbNewLine & _
" INNER JOIN " & vbNewLine & _
" aop5 " & vbNewLine & _
" ON IDENTIFICATION_DATA.NIIN " & _
" = substring(aop5.NSN,5,11) " & vbNewLine & _
" SET IDENTIFICATION_DATA.NARC = " & _
" aop5.sn "
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-04-2008, 6:04 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 712
Reputation: 369
MattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalist
Default

Jet should recognize SUBSTRING.

Code:
UPDATE id
SET id.NARC = aop5.sn
FROM IDENTIFICATION_DATA id, aop5 ao
WHERE SUBSTRING(ao.NSN, 6, 11) = id.NIIN
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-04-2008, 7:41 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Age: 45
Posts: 47
Reputation: 10
victor64 is on a distinguished programming path ahead
Default

I tried your approach with the following code, but I'm getting a "Query expression error on the AOP5.sn line. Any idea why it's not working?

Code:

Dim mySQL_Statement As String = "UPDATE ID" & vbNewLine & _
" SET ID.NARC = AOP5.sn " & vbNewLine & _
" from IDENTIFICATION_DATA, ID, AOP5 ao where SUBSTRING (ao.NSN, 6, 11) = id.NIIN"

What is the purpose of including ID and ao in the query string? Sorry I don't quiet follow the logic.

Thanks,

Victor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 12-05-2008, 6:23 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,137
Reputation: 658
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

Quote:
Originally Posted by victor64 View Post

What is the purpose of including ID and ao in the query string? Sorry I don't quiet follow the logic.
ID is an alias for the IDENTIFICATION_DATA table(, and it is used)
AO is an alias for the AOP5 table, but the alias is not used so there is no point in having it

I thought Access used MID() for substringing, not SUBSTRING
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 12-05-2008, 10:33 AM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 712
Reputation: 369
MattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalist
Default

Quote:
Originally Posted by cjard View Post
ID is an alias for the IDENTIFICATION_DATA table(, and it is used)
AO is an alias for the AOP5 table, but the alias is not used so there is no point in having it

I thought Access used MID() for substringing, not SUBSTRING
Oops used ao in the WHERE clause but not SET

Access does use MID(). I gave him an example here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 12-05-2008, 10:50 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Age: 45
Posts: 47
Reputation: 10
victor64 is on a distinguished programming path ahead
Default

I got it to work with the Mid function, Thank You very much for your Help.

Victor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 9:36 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0


For advertising opportunities click here.