Re: Specified Cast is not Valid
From: Marty U. (U._at_discussions.microsoft.com)
Date: 09/01/04
- Next message: Mark Broadbent: "Re: Adding an 'internal' control to the toolbox."
- Previous message: z. f.: "order of execution of page_load in a base and derived classes"
- In reply to: Zürcher See: "Re: Specified Cast is not Valid"
- Next in thread: Russ Gray: "Re: Specified Cast is not Valid"
- Reply: Russ Gray: "Re: Specified Cast is not Valid"
- Reply: Marty U.: "Re: Specified Cast is not Valid"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 1 Sep 2004 05:27:02 -0700
Actually the final query will have about 3 columns returned from the DB. I
tried the .Value and .value but neither worked. I still get Specified Cast is
invalid for the .Value and for the .value it states that "SqlTypes.SqlString"
does not contain a definition for 'value'.
I am stumped with this one. All I want to do is get a record from the
database based on a input parameter to the stored procedure and then set 3
public accessors to the values so I can reference them from the page.
"Zürcher See" wrote:
> Sorry I didn't read all you post, but from your code seem that you become
> only one string from the DB query or I'm wrong?
>
> For that case there is specific method in the SqlCommand
>
> object reply=SqlCommand.ExecuteScalar();
> if (reply!=System.DBNull.Value) //ok is a string and not null
>
> Don't forget to open and close the connection
>
> "Marty U." <Marty U.@discussions.microsoft.com> schrieb im Newsbeitrag
> news:3E325B79-7E3A-4EDA-BB12-D1256DBE5FE2@microsoft.com...
> > First I am switching from VB.Net to C# so I am a little rusty on syntax.
> >
> > I have a class with a couple methods and trying to assign a datareader
> value
> > to a variable which also has a public accessor for it. Below is a snippet
> and
> > where the problem occurs.
> >
> > //Declare private variable
> >
> > string name;
> >
> > public string Name {
> > get {
> > return name;
> > }
> > set {
> > name = value;
> > }
> > }
> >
> > I have a method that executes a SQL Server stored procedure returning the
> > value of a column with type varchar. Now I have done enough reading to
> > understand the GetSqlString and since I have a couple other columns such
> as
> > int from SQL server I need to find out why I am getting specified cast is
> not
> > valid when I do
> >
> > SqlDataReader dtrMyReader;
> > dtrMyReader = myCommand.ExecuteReader();
> > while (dtrMyReader.Read())
> > {
> > this.name = dtrMyReader.GetSqlString(1);
> > }
> >
> > this will not compile to an assembly because it gives me the error that
> > "Cannot implicitly convert type 'System.Data.SqlTypes.SqlString' to
> 'string'.
> > Which has to do with assigning the SqlString to the local variable "name".
> I
> > have the same problem with SQLServer integer field and probably the rest
> of
> > them to. I have found the datatype cross reference table that shows the
> ..Net
> > data types vs the sql data types.
> >
> > Can someone please give me some insight as to what I need to change to get
> > this to work. I may need to change my variable declaration and my public
> > accessor.
> >
> > Thanks
> >
> > How can I pull this information out of a datareader and assign it to
> variables
>
>
>
- Next message: Mark Broadbent: "Re: Adding an 'internal' control to the toolbox."
- Previous message: z. f.: "order of execution of page_load in a base and derived classes"
- In reply to: Zürcher See: "Re: Specified Cast is not Valid"
- Next in thread: Russ Gray: "Re: Specified Cast is not Valid"
- Reply: Russ Gray: "Re: Specified Cast is not Valid"
- Reply: Marty U.: "Re: Specified Cast is not Valid"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|