Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cast from string to type integer

0 views
Skip to first unread message

Bob

unread,
Jul 3, 2005, 7:58:00 PM7/3/05
to
Hello:

This has been driving me nuts.

Everything I do gives the same error. The bigger issue here is that it
doesn't give me a clue where the error is rising. The debugger is blank.

Thanks

Bob


Shai Goldberg

unread,
Jul 4, 2005, 1:39:02 AM7/4/05
to
Bob,

What Language do you use (VB, C#)?
Can you post an example of the string?


--
Shai

Cor Ligthert

unread,
Jul 4, 2005, 2:01:47 AM7/4/05
to
Bob,

You are sure that the string contains only numbers and ore characters which
describe the number as decimal points or exponents?

dim a as integer = Cint"1"
int a = Convert.ToInt32("1");

FYI your question is not really an ADONET question. For these questions are
the language newsgroups as by instance

microsoft.public.dotnet.languages.vb or Csharp

I hope this helps,

Cor

"Bob" <Yeah...@nospam.net> schreef in bericht
news:cY_xe.5947$H64.1520@trnddc07...

Miha Markic [MVP C#]

unread,
Jul 4, 2005, 3:42:02 AM7/4/05
to
Hi Bob,

I assume that your question is ado.net related and you get this exception
when dealing with database.
If so, I suppose that you have a integer type parameter and you are passing
a string as the value (note that parameter values aren't strong typed).

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Bob" <Yeah...@nospam.net> wrote in message
news:cY_xe.5947$H64.1520@trnddc07...

Bob

unread,
Jul 4, 2005, 10:59:15 AM7/4/05
to
Miha:

Yes right. I was trying to pass a parameter to to an Integer in a VB.NET
project to return a child row as in the question I asked on 7/1.

This paticular problem I was having was related to that. I found this
problem in that I wasn't getting a value from the parent record to pass to
the parameter for the child data adapter so it trying to pass a null value
and raising the error.

This means that I'm still trying solve my first issue. Returning child rows
without a datagrid and not having to hand code all 327 controles on my form.

daClientsMain.SelectCommand.Parameters("ClientID").Value =
CInt(txtFindClID.Text)
daClientsMain.SelectCommand.Parameters("OfficeFileNum").Value =
"0"
Me.daClientsMain.Fill(dataSet)

Dim CurrentClientID As String
CurrentClientID = Me.txtFindClID.Text.ToString()
Dim drCurrentClient As DataRow
drCurrentClient =
objdsClients.ClientsMain.FindByClientID(CurrentClientID)
Dim draPage01 As DataRow()
draPage01 = drCurrentClient.GetChildRows("PK_ClientID")
Me.Text = draPage01.Length.ToString() & " Client Pages " &
CurrentClientID

Dim drPage01 As DataRow
For Each drPage01 In draPage01
Dim ClientIDVal As String
ClientIDVal = (drPage01("ClientID"))
daPage01.SelectCommand.Parameters("ClientID").Value =
ClientIDVal
Me.daPage01.Fill(dataSet)
Next


Now I get Object reference not set to an instance of an object.

I'm woundering if it wouldn't be better to just have to Datasets and load
them both seperately. I'm also woundering if relationships in .NET are realy
worth fooling with because either way, you still have to get a value from
the parent and pass it to the child.

TIA

Bob


Cor Ligthert [MVP]

unread,
Jul 4, 2005, 11:25:17 AM7/4/05
to
Bob,

I have looked at this problem and at the problem from 1-7. I did not
understand much from it (you got no answer, so I am probably not the only
one).

Reading and reading again I get the idea that you have more tables which
have more rows which have the same "ID", which are in fact one datarow .

You want to use 325 textboxes to show those items on a form.

In that difficult case I would go for placing the textboxes dynamicly on the
form.
(How it will fit, is for me something impossible however let us asume it
fits).

In the procedure where you place them on the form, you databind than the
texboxes to the used datatables. It is not impossible that with some clever
thinking you can do that with few code.

Because as I read it is there in fact no logical relation however a phyiscal
(all tables have the same "Id" which is unique, would I not use a relation.

However confirm first if I am on the right way to understand your problem.

Cor


Bob

unread,
Jul 4, 2005, 12:58:53 PM7/4/05
to
Cor:

Sorry for being so vague in my post.

You are absolutley on the right track though.

For the text boxes, combo's etc ... I will put them into a GroupBox and use
the GroupBoxes visible property in code to show each consecutive group of
textboxes. Each group of textboxes will be bound to individual tables.

You are also correct in asuming that each table has an ID field (ClientID)
that is the same in all the tables.

Each child table will have only one record relating to the parent table when
everything is working properly.

I tried using the Bindingcontext with row positioning but often, it caused
problems because multiple users will be using it.

In some cases, for some strange reason, all the child tables didn't get a
new record in the right sequence. That means that in some tables, record
number 327 in the parent table would display record number 327 in a child
table with the wrong ClientID.

Also, a recent power failure caused me to have to go to the client location
and manualy add records to 11 tables in the proper position so they
displayed properly in the VB form.

As you can see, what I've been trying to do is fill the DA for the parent
table, get the ClientID into a variable, and pass it to a param that I
created in designer for the child table.

I built the relation and the params in designer using the Schema designer.
Gave it a name "PK_ClientID"

I will admit that I'm fairly new to .NET. I've been through my first book
wich is basic and looking for a second book with some more advanced
programing info.

For now, I have to resolve this because I can't keep running to the client
each time this happens.

TIA

Bob


Cor Ligthert [MVP]

unread,
Jul 4, 2005, 1:45:31 PM7/4/05
to
Bob,

> For the text boxes, combo's etc ... I will put them into a GroupBox and
> use the GroupBoxes visible property in code to show each consecutive group
> of textboxes. Each group of textboxes will be bound to individual tables.
>

That is a hell of a job. However I think that it goes to far as I suggest
you to change that approach

> You are also correct in asuming that each table has an ID field (ClientID)
> that is the same in all the tables.
>

So the where clause is a ? in all tables and you set from every table the
parameter correct to the correct idea (see the sample I show you bellow for
that)

> Each child table will have only one record relating to the parent table
> when everything is working properly.
>

I don't see why you need a relation, when you have 11 tables, than you can
just fill 11 tables and update 11 tables. It is not the nicest approach
however you have your 255 limit problem.

> I tried using the Bindingcontext with row positioning but often, it caused
> problems because multiple users will be using it.
>

If you read only one row from each tables with the "where" the clientid than
you have in my idea less update problems.

This is a databindingcontext for a textbox
TextBox1.DataBindings.Add(New Binding("Text", ds.Tables(0), "City"))

Dont't forget that you do in this approach for every update with the
dataadadapter
\\\
for i as integer = i to ds.tables.count -1
BindingContext(ds.Tables(i)).EndCurrentEdit()
next
///
This pushes the data from a textbox that not yet lost focus in the
datatable.

> In some cases, for some strange reason, all the child tables didn't get a
> new record in the right sequence. That means that in some tables, record
> number 327 in the parent table would display record number 327 in a child
> table with the wrong ClientID.

I would use the oledbconnection rollback method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataoledboledbtransactionclassrollbacktopic.asp

>
> Also, a recent power failure caused me to have to go to the client
> location and manualy add records to 11 tables in the proper position so
> they displayed properly in the VB form.
>
> As you can see, what I've been trying to do is fill the DA for the parent
> table, get the ClientID into a variable, and pass it to a param that I
> created in designer for the child table.
>
> I built the relation and the params in designer using the Schema designer.
> Gave it a name "PK_ClientID"
>

As I said I don't see the need for a relation, I would take them directly
using the ID.

Although that this is a sample beneath is for non typed dataset (not by the
designer created dataadapters, can you see in this sample see how to use
parameters.

http://www.windowsformsdatagridhelp.com/default.aspx?ID=550279ec-6767-44ff-aaa3-eb8b44af0137

I know this is not complete, however it becomes in my opinion to much I hope
it helps so far something.

Cor


Bob

unread,
Jul 4, 2005, 4:43:51 PM7/4/05
to
Cor:

I just got back and am reading your post. I'll take a look at all that stuff
as the day goes on.

One thing I must not have made clear is that I actually have 26 child tables
and for some reason 11 of them didn't get a new record. I had to go in and
open the DB in Access and add a record in each of the 11 of 26 tables. I
simply added a record and entered the missing ClientID in the ClientID field
and let the client handle the rest.

>As I said I don't see the need for a relation, I would take them directly
>using the ID.

I have to agree because it's been nothing but a headacke.

>Although that this is a sample beneath is for non typed dataset (not by the
>designer created dataadapters, can you see in this sample see how to use
>parameters.

I am using those methods but in an untyped DataSet

I thought I could fill the parent dataadapter, get the clientID, pass it to
the ? for my child table and then fill the child dataadapter and load the
dataset. Thats why I went with Relationship. Either way doesn't produce a
ClientID before I fill the child adapter and I end up passing NULL to the ?.
I'm assuming that the values aren't present until the data is actually
loaded into the dataset wich puts me in a visious circle so to speak wich
means that all these new visual goodies in .NET mean nothing for anything
like my app.

It's been awhile since I coded in VB6 but I remember running into the same
sort of problems with it. I always ended hand coding everything which made a
bit more than notepad with a compiler. Maybe I'll build it all in MS Access
and let them go out and get a multi license of Access

So you think maybe just having 2 DataSets? One for the parent and one for
the child?

Thanks

Bob


Cor Ligthert [MVP]

unread,
Jul 5, 2005, 2:35:37 AM7/5/05
to
Bob,

Probably your problem is easier to realise in VBNet than in Access. (Because
of the 27 tables and 3xx columns it stays something terrible)

> So you think maybe just having 2 DataSets? One for the parent and one for
> the child?
>

You can use one dataset, you only needs no relation (now I see that your
starting point is Acces, I understand why you want to use that relation).

If I start to undestand your problem well, than you have 1 major table
containing all the clientId's and other things, from which the user can make
a choose. And 26 other ones that you refresh every time using the by the
client choosen clientId (and don't forget to clear those datatables before
the fill).

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatatableclasscleartopic.asp

0 new messages