westdh
asked on
Getting the data from a comma delimited string using SQL Query
I need to loop thru and query the database to optain the users email address...
this function obtains the delimited string (csv)
I need help on the code structure...
-------------------------- ---------- ---------- ---------- ---
Shared sb As New StringBuilder
Protected Sub grdAttendees_ItemDataBound (ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Then
If Not sb.ToString().Contains(e.I tem.Cells( 0).Text) Then
sb.Append(e.Item.Cells(0). Text)
sb.Append(",")
End If
End If
Dim strKeywordID As String = sb.ToString()
Session("sbEmailAddressID" ) = strKeywordID
End Sub
-------------------------- ---------- ---------- ---------- ----
the 'strKeywordID' string is like: 154,154,155,156,
I pass this to another file using -> Session("sbEmailAddressID" )
-------------------------- ---------- ---------- ---------- ---------- ---------- -------
In this file I need to know how to parse session var sb
Dim sb As String = Session("sbEmailAddress")
Parse or split sb(",") ... and create a for loop based on the count of 'ID' .... the name of items in the string ... and then loop thru and query the sql/server database
For loop?
SELECT strBadgeName FROM i2Integration_EventRegv45_ Registrati onUser where intRegistrationUserID = @ID
next
-------------------------- ---------- ---------- ---------- ---------- ---------- -----
this function obtains the delimited string (csv)
I need help on the code structure...
--------------------------
Shared sb As New StringBuilder
Protected Sub grdAttendees_ItemDataBound
If e.Item.ItemType = ListItemType.Item Then
If Not sb.ToString().Contains(e.I
sb.Append(e.Item.Cells(0).
sb.Append(",")
End If
End If
Dim strKeywordID As String = sb.ToString()
Session("sbEmailAddressID"
End Sub
--------------------------
the 'strKeywordID' string is like: 154,154,155,156,
I pass this to another file using -> Session("sbEmailAddressID"
--------------------------
In this file I need to know how to parse session var sb
Dim sb As String = Session("sbEmailAddress")
Parse or split sb(",") ... and create a for loop based on the count of 'ID' .... the name of items in the string ... and then loop thru and query the sql/server database
For loop?
SELECT strBadgeName FROM i2Integration_EventRegv45_
next
--------------------------
hi westdh,
Hmm not very much sure what you want...
perhaps you need this
int length = Convert.ToString(Session[" sbEmailAdd ress"]).sp lit(',').L ength;
string[] ids = new string[length];
for(int i=0;i<length;i++)
{
// Use the query operations here to get the values u want
based on the ids[i] you can loop through the db.
}
I hope this helps..
Cheers....
Regards,
Amarjit Singh Dhunna
Hmm not very much sure what you want...
perhaps you need this
int length = Convert.ToString(Session["
string[] ids = new string[length];
for(int i=0;i<length;i++)
{
// Use the query operations here to get the values u want
based on the ids[i] you can loop through the db.
}
I hope this helps..
Cheers....
Regards,
Amarjit Singh Dhunna
Also @reza_rad Split(",") should be Split(',') :-)
Cheers....
Regards,
Amarjit Singh Dhunna
ASKER
How about this... also I have a problem with converting the C# to vb on the for a length statement. But does this help explain what I am trying to do
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
Dim strEmailAddress As String
Dim dtVolumeOrder As New DataTable()
Dim length As Integer = Convert.ToString(Session(" sbEmailAdd ress")).Sp lit(","c). Length
Dim ids As String() = New String(length - 1) {}
For i As Integer = 1 To 10; i<length; i++)'loop through the db gettin email address
Dim strSelectCommand As String = " SELECT strBadgeName[i] FROM i2Integration_EventRegv45_ Registrati onUser where intRegistrationUserID = ids[i]"
Using sqlConn As New SqlConnection(Configuratio nManager.C onnectionS trings("Si teSqlServe r").Connec tionString )
Using adapPatientBills As New SqlDataAdapter(strSelectCo mmand, sqlConn)
adapPatientBills.Fill(dtVo lumeOrder)
End Using
End Using
strEmailAddress = strEmailAddress + strSelectCommand + ","
' build string of email addresses seperated by ','
Next i
--------------------------
Dim strEmailAddress As String
Dim dtVolumeOrder As New DataTable()
Dim length As Integer = Convert.ToString(Session("
Dim ids As String() = New String(length - 1) {}
For i As Integer = 1 To 10; i<length; i++)'loop through the db gettin email address
Dim strSelectCommand As String = " SELECT strBadgeName[i] FROM i2Integration_EventRegv45_
Using sqlConn As New SqlConnection(Configuratio
Using adapPatientBills As New SqlDataAdapter(strSelectCo
adapPatientBills.Fill(dtVo
End Using
End Using
strEmailAddress = strEmailAddress + strSelectCommand + ","
' build string of email addresses seperated by ','
Next i
ASKER
here i have correct some convert C# to vb error: check this out
Dim strEmailAddress As String = ""
Dim dtVolumeOrder As New DataTable()
Dim length As Integer = Convert.ToString(Session(" sbEmailAdd ress")).Sp lit(","c). Length
Dim ids As String() = New String(length - 1) {}
For i As Integer = 0 To length - 1
Dim strSelectCommand As String = " SELECT strBadgeName[i] FROM i2Integration_EventRegv45_ Registrati onUser where intRegistrationUserID = ids[i]"
Using sqlConn As New SqlConnection(Configuratio nManager.C onnectionS trings("Si teSqlServe r").Connec tionString )
Using adapPatientBills As New SqlDataAdapter(strSelectCo mmand, sqlConn)
adapPatientBills.Fill(dtVo lumeOrder)
End Using
End Using
strEmailAddress = strEmailAddress + strSelectCommand + "," ' build string of email addresses seperated by ','
Next
Dim strEmailAddress As String = ""
Dim dtVolumeOrder As New DataTable()
Dim length As Integer = Convert.ToString(Session("
Dim ids As String() = New String(length - 1) {}
For i As Integer = 0 To length - 1
Dim strSelectCommand As String = " SELECT strBadgeName[i] FROM i2Integration_EventRegv45_
Using sqlConn As New SqlConnection(Configuratio
Using adapPatientBills As New SqlDataAdapter(strSelectCo
adapPatientBills.Fill(dtVo
End Using
End Using
strEmailAddress = strEmailAddress + strSelectCommand + "," ' build string of email addresses seperated by ','
Next
ASKER
got this error A critical error has occurred. Incorrect syntax near 'i'.
Dim strEmailAddress As String = ""
Dim dtVolumeOrder As New DataTable()
Dim length As Integer = Convert.ToString(Session("
Dim ids As String() = New String(length - 1) {}
For i As Integer = 0 To length - 1
Dim strSelectCommand As String = " SELECT strBadgeName[i] FROM i2Integration_EventRegv45_
Using sqlConn As New SqlConnection(Configuratio
Using adapPatientBills As New SqlDataAdapter(strSelectCo
adapPatientBills.Fill(dtVo
End Using
End Using
strEmailAddress = strEmailAddress + strSelectCommand + "," ' build string of email addresses seperated by ','
Next
change this line:
Dim length As Integer = Convert.ToString(Session(" sbEmailAdd ress")).Sp lit(","c). Length
to
Dim length As Integer = Convert.ToString(Session(" sbEmailAdd ress")).Sp lit(",").L ength
and say what error do you receive?
Dim length As Integer = Convert.ToString(Session("
to
Dim length As Integer = Convert.ToString(Session("
and say what error do you receive?
well i m not expert of VB but still tried bit
hope it helps
hope it helps
Dim strEmailAddress As String = ""
Dim dtVolumeOrder As New DataTable()
Dim length As Integer = Convert.ToString("amarjit,singh,dhunna").Split(",").Length
Dim ids As String()
Dim strSelectCommand As String
ids = Convert.ToString("amarjit,singh.dhunna").Split(",")
For i As Integer = 0 To length - 1
strSelectCommand = "SELECT strBadgeName FROM i2Integration_EventRegv45_RegistrationUser where intRegistrationUserID = " & ids(i)
'Using sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
'Using adapPatientBills As New SqlDataAdapter(strSelectCommand, sqlConn)
'adapPatientBills.Fill(dtVolumeOrder)
' End Using
' End Using
'strEmailAddress = strEmailAddress + strSelectCommand + "," ' build string of email addresses seperated by ','
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
A critical error has occurred. Incorrect syntax near 'i'. is thier a problem with the way I have ids[i] inserted inthe select string.
SELECT strBadgeName[i] FROM i2Integration_EventRegv45_ Registrati onUser where intRegistrationUserID = ids[i]"
also I find I am still picking up only one I ID in my previous rountine
when I submit the email address xxxxxx@charter.net, yyyyyyyyy@charter.net
but some times it works??? especially if I go away from my Pc for sometime...
If e.Item.ItemType = ListItemType.Item Then
If Not sb.ToString().Contains(e.I tem.Cells( 0).Text) Then
sb.Append(e.Item.Cells(0). Text)
sb.Append(",")
End If
End If
SELECT strBadgeName[i] FROM i2Integration_EventRegv45_
also I find I am still picking up only one I ID in my previous rountine
when I submit the email address xxxxxx@charter.net, yyyyyyyyy@charter.net
but some times it works??? especially if I go away from my Pc for sometime...
If e.Item.ItemType = ListItemType.Item Then
If Not sb.ToString().Contains(e.I
sb.Append(e.Item.Cells(0).
sb.Append(",")
End If
End If
ASKER
current script
Dim strEmailAddress As String = ""
Dim dtVolumeOrder As New DataTable()
Dim length As Integer = Convert.ToString(Session(" sbEmailAdd ress")).Sp lit(",").L ength
Dim ids As String() = New String(length - 1) {}
For i As Integer = 0 To length - 1
Dim strSelectCommand As String = "SELECT strBadgeName[i] FROM i2Integration_EventRegv45_ Registrati onUser where intRegistrationUserID = ids[i]"
Using sqlConn As New SqlConnection(Configuratio nManager.C onnectionS trings("Si teSqlServe r").Connec tionString )
Using adapPatientBills As New SqlDataAdapter(strSelectCo mmand, sqlConn)
adapPatientBills.Fill(dtVo lumeOrder)
End Using
End Using
strEmailAddress = strEmailAddress + strSelectCommand + "," ' build string of email addresses seperated by ','
Next
Dim strEmailAddress As String = ""
Dim dtVolumeOrder As New DataTable()
Dim length As Integer = Convert.ToString(Session("
Dim ids As String() = New String(length - 1) {}
For i As Integer = 0 To length - 1
Dim strSelectCommand As String = "SELECT strBadgeName[i] FROM i2Integration_EventRegv45_
Using sqlConn As New SqlConnection(Configuratio
Using adapPatientBills As New SqlDataAdapter(strSelectCo
adapPatientBills.Fill(dtVo
End Using
End Using
strEmailAddress = strEmailAddress + strSelectCommand + "," ' build string of email addresses seperated by ','
Next
I think it's better to explain what you want exactly, your code has lot's of error.
so describe what you want exactly?
so describe what you want exactly?
have you tried my code?
ASKER
Thanks I am going back to my old way, even though it not working right yet
strange i the solution was initiated and provided correctly by me.. ):
do you want to split a string by comma, if yes use string.Split(",") this will return array of string
if you want anything else explain more, I have no idea what you want to do already