UniqueIdentifier Sql Data and Parameters

G

Guest

Hi everybody,

I have a column in one of tables in one of the sql server that has a data
type of
UniqueIdentifier. Now, I am supplying a value to used this column as filter
to get
specific record.

Note: strCompId is in string datatype.

Code:
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid", OleDbType.Guid,
Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code shown above causes a conversion error.
There is no conversion from string to GUID. Is there?

Code:
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.VarChar, Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code above returns that "@compid" parameter does not exist.

How can I solved this?

Thanks.

den2005
 
M

Matt Noonan

Well, I hate to sound like I'm not answering the question, but why are you
using the OleDb client in place of SqlClient? You're potentially harming
your application's performance by doing so.

As for @compid not being found, OleDb only uses a '?' placeholder (whether
you gave it a name or not), so if you ask for the parameter by name it's
likely it won't be found.

My advice would be to switch to the SqlClient, where you can name your
parameters and retrieve their values.
 
G

Guest

Hi Matt,
I am using the data for crystal report.

dennis
--
MCP Year 2005, Philippines


Matt Noonan said:
Well, I hate to sound like I'm not answering the question, but why are you
using the OleDb client in place of SqlClient? You're potentially harming
your application's performance by doing so.

As for @compid not being found, OleDb only uses a '?' placeholder (whether
you gave it a name or not), so if you ask for the parameter by name it's
likely it won't be found.

My advice would be to switch to the SqlClient, where you can name your
parameters and retrieve their values.


--
Matt Noonan
EasyObjects.NET: The O/RM for the Enterprise Library
http://www.easyobjects.net


den 2005 said:
Hi everybody,

I have a column in one of tables in one of the sql server that has a data
type of
UniqueIdentifier. Now, I am supplying a value to used this column as
filter
to get
specific record.

Note: strCompId is in string datatype.

Code:
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.Guid,
Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code shown above causes a conversion error.
There is no conversion from string to GUID. Is there?

Code:
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.VarChar, Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code above returns that "@compid" parameter does not exist.

How can I solved this?

Thanks.

den2005
 
M

Matt Noonan

Ah, that explains a lot. The last time I used Crystal, I ended up using
typed DataSets to hold the data and binding the report that way.


--
Matt Noonan
EasyObjects.NET: The O/RM for the Enterprise Library
http://www.easyobjects.net


den 2005 said:
Hi Matt,
I am using the data for crystal report.

dennis
--
MCP Year 2005, Philippines


Matt Noonan said:
Well, I hate to sound like I'm not answering the question, but why are
you
using the OleDb client in place of SqlClient? You're potentially harming
your application's performance by doing so.

As for @compid not being found, OleDb only uses a '?' placeholder
(whether
you gave it a name or not), so if you ask for the parameter by name it's
likely it won't be found.

My advice would be to switch to the SqlClient, where you can name your
parameters and retrieve their values.


--
Matt Noonan
EasyObjects.NET: The O/RM for the Enterprise Library
http://www.easyobjects.net


den 2005 said:
Hi everybody,

I have a column in one of tables in one of the sql server that has a
data
type of
UniqueIdentifier. Now, I am supplying a value to used this column as
filter
to get
specific record.

Note: strCompId is in string datatype.

Code:
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.Guid,
Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code shown above causes a conversion error.
There is no conversion from string to GUID. Is there?

Code:
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.VarChar, Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code above returns that "@compid" parameter does not exist.

How can I solved this?

Thanks.

den2005
 
G

Guest

Thanks, Cor and Matt.
My problem about crystal report does not stopd there.
I am using this Guid as filter to the where clause unfortunately it is not
working.
How do transfer the string value of certain dropdownlsit control to the
crystal report? Start Date and End Date.

This part is first page, the second page I might need to use SubReport,
which I am new with this.

The first part is a summary of the second page.

There is Company Field which displays company name from db1 of table1,
Company ID id DataValue of dropdownlist 'ddlITP'.

Now, Address Field is located on another database of another server. The
link column is COGUID.

both CompanyID and COGUID is in UniqueIdentifier (Sql Data Type)

Code:
Try
Dim connectString As String = "Provider=SQLOLEDB;data
source=serv1;initial catalog=db1;. . ."

''Create and open a connection using the connection string
Dim adoOleDbConnection As New OleDbConnection(connectString)

''Build a SQL statement to query the datasource
Dim sqlString As String = ""
sqlString = "Select * From table1"

''Retrieve the data using the SQL statement and existing
connection
Dim adoOleDbDataAdapter As New OleDbDataAdapter(sqlString,
adoOleDbConnection)

''Create a instance of a Dataset
Dim DataSet As New DataSet()

''Fill the dataset with the data retrieved.  The name of the table
''in the dataset must be the same as the table name in the report.
adoOleDbDataAdapter.Fill(DataSet, "table1")

Dim connectString2 As String = "Provider=SQLOLEDB;data
source=serv2;. . ."

''Create and open a connection using the connection string
Dim adoOleDbConnection2 As New OleDbConnection(connectString2)
'Dim adoSqlConnection As New SqlConnection(connectString)

''Build a SQL statement to query the datasource
Dim sqlString2 As String = ""
sqlString2 = "Select * From table2 Where COGUID = ?"

''Retrieve the data using the SQL statement and existing
connection
Dim adoOleDbDataAdapter2 As New OleDbDataAdapter(sqlString2,
adoOleDbConnection2)
'Dim adoSqlDataAdapter As New SqlDataAdapter(sqlString,
adoSqlConnection)
If Me.strCompId = "" Then
Me.strCompId = Me.ddlITP.SelectedItem.Value.ToString()
End If

'Dim coguid As Guid = DirectCast(Me.strCompId, Guid)
'Dim coguid As Guid = CType(Me.ddlITP.SelectedItem, Guid)
Dim coguid As New Guid(Me.strCompId)

adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@COGUID",
OleDbType.VarChar, Me.strCompId.Length, "COGUID").Value = Me.strCompId

''Create a instance of a Dataset
Dim DataSet2 As New DataSet()

''Fill the dataset with the data retrieved.  The name of the table
''in the dataset must be the same as the table name in the report.
adoOleDbDataAdapter2.Fill(DataSet, "table2")

''Create an instance of the strongly-typed report object
Dim crReportDocument As New Report1C()

''Pass the populated dataset to the report
crReportDocument.SetDataSource(DataSet)

Dim folder As String = System.IO.Directory.GetCurrentDirectory()
Dim path As String

path = "c:\inetpub\wwwroot\accountweb\Report1C.rpt"

If System.IO.File.Exists(path) = True Then

Dim crConnectionInfo As New ConnectionInfo()
With crConnectionInfo
.ServerName = "serv1"
.DatabaseName = "db1"
.UserID = "user"
.Password = "pass"
End With
'With crConnectionInfo
'    .ServerName = "serv2"
'    .DatabaseName = "db1"
'    .UserID = "user"
'    .Password = "password"
'End With

'Get the tables collection from the report object
Dim crDatabase As Database = crReportDocument.Database
Dim crTables As Tables = crDatabase.Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo

'Apply the logon information to each table in the collection
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next

Me.crvITPReport.ReportSource = crReportDocument


End If
Catch exp As Exception


End Try
[\code]

den2005
--
MCP Year 2005, Philippines


[QUOTE="Cor Ligthert"]
Den,

Yes there is a conversion from string to Guid, it is in the constructor of
the GUID

http://msdn2.microsoft.com/en-us/library/system.guid.guid(VS.80).aspx

The String Guid has to be correct of course, so you have to use the try
catch.

I hope this helps,

Cor

[QUOTE="den 2005"]
Hi everybody,

I have a column in one of tables in one of the sql server that has a data
type of
UniqueIdentifier. Now, I am supplying a value to used this column as
filter
to get
specific record.

Note: strCompId is in string datatype.

[code]
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.Guid,
Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code shown above causes a conversion error.
There is no conversion from string to GUID. Is there?

Code:
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.VarChar, Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code above returns that "@compid" parameter does not exist.

How can I solved this?

Thanks.

den2005[/QUOTE]
[/QUOTE]
 
C

Cor Ligthert [MVP]

Matt,

Did you ask this already in the newsgroup.

Microsoft.public.dotnet.languages.vb

In my idea, are Crystal report questions seldom completely answered in these
dotnet newsgroup. However in that newsgroup is somebody who does that the
best.

Not to send you away by the way.

Cor

den 2005 said:
Thanks, Cor and Matt.
My problem about crystal report does not stopd there.
I am using this Guid as filter to the where clause unfortunately it is not
working.
How do transfer the string value of certain dropdownlsit control to the
crystal report? Start Date and End Date.

This part is first page, the second page I might need to use SubReport,
which I am new with this.

The first part is a summary of the second page.

There is Company Field which displays company name from db1 of table1,
Company ID id DataValue of dropdownlist 'ddlITP'.

Now, Address Field is located on another database of another server. The
link column is COGUID.

both CompanyID and COGUID is in UniqueIdentifier (Sql Data Type)

Code:
Try
Dim connectString As String = "Provider=SQLOLEDB;data
source=serv1;initial catalog=db1;. . ."

''Create and open a connection using the connection string
Dim adoOleDbConnection As New OleDbConnection(connectString)

''Build a SQL statement to query the datasource
Dim sqlString As String = ""
sqlString = "Select * From table1"

''Retrieve the data using the SQL statement and existing
connection
Dim adoOleDbDataAdapter As New OleDbDataAdapter(sqlString,
adoOleDbConnection)

''Create a instance of a Dataset
Dim DataSet As New DataSet()

''Fill the dataset with the data retrieved.  The name of the
table
''in the dataset must be the same as the table name in the
report.
adoOleDbDataAdapter.Fill(DataSet, "table1")

Dim connectString2 As String = "Provider=SQLOLEDB;data
source=serv2;. . ."

''Create and open a connection using the connection string
Dim adoOleDbConnection2 As New OleDbConnection(connectString2)
'Dim adoSqlConnection As New SqlConnection(connectString)

''Build a SQL statement to query the datasource
Dim sqlString2 As String = ""
sqlString2 = "Select * From table2 Where COGUID = ?"

''Retrieve the data using the SQL statement and existing
connection
Dim adoOleDbDataAdapter2 As New OleDbDataAdapter(sqlString2,
adoOleDbConnection2)
'Dim adoSqlDataAdapter As New SqlDataAdapter(sqlString,
adoSqlConnection)
If Me.strCompId = "" Then
Me.strCompId = Me.ddlITP.SelectedItem.Value.ToString()
End If

'Dim coguid As Guid = DirectCast(Me.strCompId, Guid)
'Dim coguid As Guid = CType(Me.ddlITP.SelectedItem, Guid)
Dim coguid As New Guid(Me.strCompId)

adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@COGUID",
OleDbType.VarChar, Me.strCompId.Length, "COGUID").Value = Me.strCompId

''Create a instance of a Dataset
Dim DataSet2 As New DataSet()

''Fill the dataset with the data retrieved.  The name of the
table
''in the dataset must be the same as the table name in the
report.
adoOleDbDataAdapter2.Fill(DataSet, "table2")

''Create an instance of the strongly-typed report object
Dim crReportDocument As New Report1C()

''Pass the populated dataset to the report
crReportDocument.SetDataSource(DataSet)

Dim folder As String =
System.IO.Directory.GetCurrentDirectory()
Dim path As String

path = "c:\inetpub\wwwroot\accountweb\Report1C.rpt"

If System.IO.File.Exists(path) = True Then

Dim crConnectionInfo As New ConnectionInfo()
With crConnectionInfo
.ServerName = "serv1"
.DatabaseName = "db1"
.UserID = "user"
.Password = "pass"
End With
'With crConnectionInfo
'    .ServerName = "serv2"
'    .DatabaseName = "db1"
'    .UserID = "user"
'    .Password = "password"
'End With

'Get the tables collection from the report object
Dim crDatabase As Database = crReportDocument.Database
Dim crTables As Tables = crDatabase.Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo

'Apply the logon information to each table in the
collection
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next

Me.crvITPReport.ReportSource = crReportDocument


End If
Catch exp As Exception


End Try
[\code]

den2005
--
MCP Year 2005, Philippines


[QUOTE="Cor Ligthert"]
Den,

Yes there is a conversion from string to Guid, it is in the constructor
of
the GUID

http://msdn2.microsoft.com/en-us/library/system.guid.guid(VS.80).aspx

The String Guid has to be correct of course, so you have to use the try
catch.

I hope this helps,

Cor

[QUOTE="den 2005"]
Hi everybody,

I have a column in one of tables in one of the sql server that has a
data
type of
UniqueIdentifier. Now, I am supplying a value to used this column as
filter
to get
specific record.

Note: strCompId is in string datatype.

[code]
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.Guid,
Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code shown above causes a conversion error.
There is no conversion from string to GUID. Is there?

Code:
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.VarChar, Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code above returns that "@compid" parameter does not exist.

How can I solved this?

Thanks.

den2005
[/QUOTE][/QUOTE]
 
G

Guest

This problem has been resolved.

den2005
--
MCP Year 2005, Philippines


Cor Ligthert said:
Matt,

Did you ask this already in the newsgroup.

Microsoft.public.dotnet.languages.vb

In my idea, are Crystal report questions seldom completely answered in these
dotnet newsgroup. However in that newsgroup is somebody who does that the
best.

Not to send you away by the way.

Cor

den 2005 said:
Thanks, Cor and Matt.
My problem about crystal report does not stopd there.
I am using this Guid as filter to the where clause unfortunately it is not
working.
How do transfer the string value of certain dropdownlsit control to the
crystal report? Start Date and End Date.

This part is first page, the second page I might need to use SubReport,
which I am new with this.

The first part is a summary of the second page.

There is Company Field which displays company name from db1 of table1,
Company ID id DataValue of dropdownlist 'ddlITP'.

Now, Address Field is located on another database of another server. The
link column is COGUID.

both CompanyID and COGUID is in UniqueIdentifier (Sql Data Type)

Code:
Try
Dim connectString As String = "Provider=SQLOLEDB;data
source=serv1;initial catalog=db1;. . ."

''Create and open a connection using the connection string
Dim adoOleDbConnection As New OleDbConnection(connectString)

''Build a SQL statement to query the datasource
Dim sqlString As String = ""
sqlString = "Select * From table1"

''Retrieve the data using the SQL statement and existing
connection
Dim adoOleDbDataAdapter As New OleDbDataAdapter(sqlString,
adoOleDbConnection)

''Create a instance of a Dataset
Dim DataSet As New DataSet()

''Fill the dataset with the data retrieved.  The name of the
table
''in the dataset must be the same as the table name in the
report.
adoOleDbDataAdapter.Fill(DataSet, "table1")

Dim connectString2 As String = "Provider=SQLOLEDB;data
source=serv2;. . ."

''Create and open a connection using the connection string
Dim adoOleDbConnection2 As New OleDbConnection(connectString2)
'Dim adoSqlConnection As New SqlConnection(connectString)

''Build a SQL statement to query the datasource
Dim sqlString2 As String = ""
sqlString2 = "Select * From table2 Where COGUID = ?"

''Retrieve the data using the SQL statement and existing
connection
Dim adoOleDbDataAdapter2 As New OleDbDataAdapter(sqlString2,
adoOleDbConnection2)
'Dim adoSqlDataAdapter As New SqlDataAdapter(sqlString,
adoSqlConnection)
If Me.strCompId = "" Then
Me.strCompId = Me.ddlITP.SelectedItem.Value.ToString()
End If

'Dim coguid As Guid = DirectCast(Me.strCompId, Guid)
'Dim coguid As Guid = CType(Me.ddlITP.SelectedItem, Guid)
Dim coguid As New Guid(Me.strCompId)

adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@COGUID",
OleDbType.VarChar, Me.strCompId.Length, "COGUID").Value = Me.strCompId

''Create a instance of a Dataset
Dim DataSet2 As New DataSet()

''Fill the dataset with the data retrieved.  The name of the
table
''in the dataset must be the same as the table name in the
report.
adoOleDbDataAdapter2.Fill(DataSet, "table2")

''Create an instance of the strongly-typed report object
Dim crReportDocument As New Report1C()

''Pass the populated dataset to the report
crReportDocument.SetDataSource(DataSet)

Dim folder As String =
System.IO.Directory.GetCurrentDirectory()
Dim path As String

path = "c:\inetpub\wwwroot\accountweb\Report1C.rpt"

If System.IO.File.Exists(path) = True Then

Dim crConnectionInfo As New ConnectionInfo()
With crConnectionInfo
.ServerName = "serv1"
.DatabaseName = "db1"
.UserID = "user"
.Password = "pass"
End With
'With crConnectionInfo
'    .ServerName = "serv2"
'    .DatabaseName = "db1"
'    .UserID = "user"
'    .Password = "password"
'End With

'Get the tables collection from the report object
Dim crDatabase As Database = crReportDocument.Database
Dim crTables As Tables = crDatabase.Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo

'Apply the logon information to each table in the
collection
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next

Me.crvITPReport.ReportSource = crReportDocument


End If
Catch exp As Exception


End Try
[\code]

den2005
--
MCP Year 2005, Philippines


[QUOTE="Cor Ligthert"]
Den,

Yes there is a conversion from string to Guid, it is in the constructor
of
the GUID

http://msdn2.microsoft.com/en-us/library/system.guid.guid(VS.80).aspx

The String Guid has to be correct of course, so you have to use the try
catch.

I hope this helps,

Cor

"den 2005" <[email protected]> schreef in bericht
Hi everybody,

I have a column in one of tables in one of the sql server that has a
data
type of
UniqueIdentifier. Now, I am supplying a value to used this column as
filter
to get
specific record.

Note: strCompId is in string datatype.

[code]
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.Guid,
Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code shown above causes a conversion error.
There is no conversion from string to GUID. Is there?

Code:
adoOleDbDataAdapter2.SelectCommand.Parameters.Add("@compid",
OleDbType.VarChar, Me.strCompId.Length, "COGUID").Value = Me.strCompId

The code above returns that "@compid" parameter does not exist.

How can I solved this?

Thanks.

den2005
[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top