By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,978 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,978 IT Pros & Developers. It's quick & easy.

ExecuteNonQuery - problem

P: n/a
b_r
Hi,

I'm trying to make a simple operation (insert into DB) in VB 2005 and
SQL Server.

The code is as follows:

Dim sConnectionString As String = _
"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\DB.mdf....

Dim cnDB As New SqlConnection(sConnectionString)
cnDB.Open()
Dim strSQL As String
strSQL = "INSERT INTO Company (CompanyName) VALUES ('four')"
Dim command As SqlCommand = New SqlCommand(strSQL, cnDB)
command.ExecuteNonQuery()
cnDB.Close()

But the row is not inserted into DB and also there is no any error.

Initialy I wanted to use stored procedure but in order to make it
working I made the simplest operation - without success...

Do you have any idea what is wrong?

Regards
BR

Dec 30 '06 #1
Share this Question
Share on Google+
22 Replies


P: n/a
Dubug using this construct and see what the value of ex.message tells you

Try

'//Your Code

Catch ex as Exception '//breakpoint here

End try

"b_r" <b_r@wp'_cut_it'.plwrote in message
news:2d***************************@news.chello.pl. ..
Hi,

I'm trying to make a simple operation (insert into DB) in VB 2005 and SQL
Server.

The code is as follows:

Dim sConnectionString As String = _
"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\DB.mdf....

Dim cnDB As New SqlConnection(sConnectionString)
cnDB.Open()
Dim strSQL As String
strSQL = "INSERT INTO Company (CompanyName) VALUES ('four')"
Dim command As SqlCommand = New SqlCommand(strSQL, cnDB)
command.ExecuteNonQuery()
cnDB.Close()

But the row is not inserted into DB and also there is no any error.

Initialy I wanted to use stored procedure but in order to make it working
I made the simplest operation - without success...

Do you have any idea what is wrong?

Regards
BR

Dec 30 '06 #2

P: n/a
b_r
The ex message shows nothing (ex = nothing) and row is not inserted.

Just Me napisał(a):
Dubug using this construct and see what the value of ex.message tells you

Try

'//Your Code

Catch ex as Exception '//breakpoint here

End try

"b_r" <b_r@wp'_cut_it'.plwrote in message
news:2d***************************@news.chello.pl. ..
>Hi,

I'm trying to make a simple operation (insert into DB) in VB 2005 and SQL
Server.

The code is as follows:

Dim sConnectionString As String = _
"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirecto ry|\DB.mdf....

Dim cnDB As New SqlConnection(sConnectionString)
cnDB.Open()
Dim strSQL As String
strSQL = "INSERT INTO Company (CompanyName) VALUES ('four')"
Dim command As SqlCommand = New SqlCommand(strSQL, cnDB)
command.ExecuteNonQuery()
cnDB.Close()

But the row is not inserted into DB and also there is no any error.

Initialy I wanted to use stored procedure but in order to make it working
I made the simplest operation - without success...

Do you have any idea what is wrong?

Regards
BR

Dec 30 '06 #3

P: n/a
'// Is this correct ? should it not be just CompanyName ?
Company (CompanyName)

strSQL = "INSERT INTO Company (CompanyName) VALUES ('four')"

"b_r" <b_r@wp'_cut_it'.plwrote in message
news:ca***************************@news.chello.pl. ..
The ex message shows nothing (ex = nothing) and row is not inserted.

Just Me napisał(a):
>Dubug using this construct and see what the value of ex.message tells you

Try

'//Your Code

Catch ex as Exception '//breakpoint here

End try

"b_r" <b_r@wp'_cut_it'.plwrote in message
news:2d***************************@news.chello.pl ...
>>Hi,

I'm trying to make a simple operation (insert into DB) in VB 2005 and
SQL Server.

The code is as follows:

Dim sConnectionString As String = _
"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirect ory|\DB.mdf....

Dim cnDB As New SqlConnection(sConnectionString)
cnDB.Open()
Dim strSQL As String
strSQL = "INSERT INTO Company (CompanyName) VALUES ('four')"
Dim command As SqlCommand = New SqlCommand(strSQL, cnDB)
command.ExecuteNonQuery()
cnDB.Close()

But the row is not inserted into DB and also there is no any error.

Initialy I wanted to use stored procedure but in order to make it
working I made the simplest operation - without success...

Do you have any idea what is wrong?

Regards
BR
Dec 30 '06 #4

P: n/a
Try this, and see what it says about the rows updated:

Dim RecordsAffected As Integer = command.ExecuteNonQuery()
Debug.WriteLine("Query Affected {0} row(s).", RecordsAffected)

Does it say 0?

If so, can you open SQLServer and try the query there?

Do you have write access to the table?

Does the table have a different field that is the primary
key and you're not setting the value for that?

Is the record you're trying to add already there?

Robin S.
----------------------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:2d***************************@news.chello.pl. ..
Hi,

I'm trying to make a simple operation (insert into DB) in VB 2005 and
SQL Server.

The code is as follows:

Dim sConnectionString As String = _
"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\DB.mdf....

Dim cnDB As New SqlConnection(sConnectionString)
cnDB.Open()
Dim strSQL As String
strSQL = "INSERT INTO Company (CompanyName) VALUES ('four')"
Dim command As SqlCommand = New SqlCommand(strSQL, cnDB)
command.ExecuteNonQuery()
cnDB.Close()

But the row is not inserted into DB and also there is no any error.

Initialy I wanted to use stored procedure but in order to make it
working I made the simplest operation - without success...

Do you have any idea what is wrong?

Regards
BR

Dec 30 '06 #5

P: n/a
b_r
Thank you for suggestions.

RecordsAffected value is equal to 1 - so it is correct value ... but new
row doesn't appear in the table

Query in SQLServer works fine...
RobinS napisał(a):
Try this, and see what it says about the rows updated:

Dim RecordsAffected As Integer = command.ExecuteNonQuery()
Debug.WriteLine("Query Affected {0} row(s).", RecordsAffected)

Does it say 0?

If so, can you open SQLServer and try the query there?

Do you have write access to the table?

Does the table have a different field that is the primary
key and you're not setting the value for that?

Is the record you're trying to add already there?

Robin S.
----------------------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:2d***************************@news.chello.pl. ..
>Hi,

I'm trying to make a simple operation (insert into DB) in VB 2005 and
SQL Server.

The code is as follows:

Dim sConnectionString As String = _
"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirecto ry|\DB.mdf....

Dim cnDB As New SqlConnection(sConnectionString)
cnDB.Open()
Dim strSQL As String
strSQL = "INSERT INTO Company (CompanyName) VALUES ('four')"
Dim command As SqlCommand = New SqlCommand(strSQL, cnDB)
command.ExecuteNonQuery()
cnDB.Close()

But the row is not inserted into DB and also there is no any error.

Initialy I wanted to use stored procedure but in order to make it
working I made the simplest operation - without success...

Do you have any idea what is wrong?

Regards
BR

Dec 30 '06 #6

P: n/a
Put in a breakpoint at the Debug.WriteLine statement. Run it up until
that
point, and then go look in your database and see if the record is there.

If it's not there, open your immediate window and check your connection
string and make sure you're really connecting to the right database.

Debug.Print sConnectionString

If you are connecting to the right database, try reading the record back
right after you write it, ***using the same connection***.

strSQL = "SELECT CompanyName FROM Company WHERE CompanyName = 'four' "
Dim command2 As SqlCommand = New SqlCommand(strSQL, cnDB)
Dim da As New SqlDataAdapter()
da.SelectCommand = command2
Dim dt as New DataTable()
da.fill(dt)
For Each dr As DataRow in dt.rows
Debug.print "Found CompanyName: " & dt.rows("CompanyName")
Next dr
cnDB.Close()

If that doesn't work, and the table isn't huge, try writing the whole
table and
see if it looks right.

The only thing I can think of is that you are not pointing to the same
database
you think you are, especially since you get a rowcount of 1 back when
you
execute the insert query. If there was any problem on the SQLServer
side,
it would return 0. That's my opinion, anyway.

Robin S.
--------------------------------------

"b_r" <b_r@wp'_cut_it'.plwrote in message
news:dc**************************@news.chello.pl.. .
Thank you for suggestions.

RecordsAffected value is equal to 1 - so it is correct value ... but
new row doesn't appear in the table

Query in SQLServer works fine...
RobinS napisał(a):
>Try this, and see what it says about the rows updated:

Dim RecordsAffected As Integer = command.ExecuteNonQuery()
Debug.WriteLine("Query Affected {0} row(s).", RecordsAffected)

Does it say 0?

If so, can you open SQLServer and try the query there?

Do you have write access to the table?

Does the table have a different field that is the primary
key and you're not setting the value for that?

Is the record you're trying to add already there?

Robin S.
----------------------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:2d***************************@news.chello.pl ...
>>Hi,

I'm trying to make a simple operation (insert into DB) in VB 2005
and SQL Server.

The code is as follows:

Dim sConnectionString As String = _
"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirect ory|\DB.mdf....

Dim cnDB As New SqlConnection(sConnectionString)
cnDB.Open()
Dim strSQL As String
strSQL = "INSERT INTO Company (CompanyName) VALUES ('four')"
Dim command As SqlCommand = New SqlCommand(strSQL, cnDB)
command.ExecuteNonQuery()
cnDB.Close()

But the row is not inserted into DB and also there is no any error.

Initialy I wanted to use stored procedure but in order to make it
working I made the simplest operation - without success...

Do you have any idea what is wrong?

Regards
BR
Dec 30 '06 #7

P: n/a
b_r
Database is correct - for sure...

When I want to verify inserted row I got the following information:

A first chance exception of type 'System.InvalidCastException' occurred
in Microsoft.VisualBasic.dll

RobinS napisał(a):
Put in a breakpoint at the Debug.WriteLine statement. Run it up until
that
point, and then go look in your database and see if the record is there.

If it's not there, open your immediate window and check your connection
string and make sure you're really connecting to the right database.

Debug.Print sConnectionString

If you are connecting to the right database, try reading the record back
right after you write it, ***using the same connection***.

strSQL = "SELECT CompanyName FROM Company WHERE CompanyName = 'four' "
Dim command2 As SqlCommand = New SqlCommand(strSQL, cnDB)
Dim da As New SqlDataAdapter()
da.SelectCommand = command2
Dim dt as New DataTable()
da.fill(dt)
For Each dr As DataRow in dt.rows
Debug.print "Found CompanyName: " & dt.rows("CompanyName")
Next dr
cnDB.Close()

If that doesn't work, and the table isn't huge, try writing the whole
table and
see if it looks right.

The only thing I can think of is that you are not pointing to the same
database
you think you are, especially since you get a rowcount of 1 back when
you
execute the insert query. If there was any problem on the SQLServer
side,
it would return 0. That's my opinion, anyway.

Robin S.
--------------------------------------

"b_r" <b_r@wp'_cut_it'.plwrote in message
news:dc**************************@news.chello.pl.. .
>Thank you for suggestions.

RecordsAffected value is equal to 1 - so it is correct value ... but
new row doesn't appear in the table

Query in SQLServer works fine...
RobinS napisał(a):
>>Try this, and see what it says about the rows updated:

Dim RecordsAffected As Integer = command.ExecuteNonQuery()
Debug.WriteLine("Query Affected {0} row(s).", RecordsAffected)

Does it say 0?

If so, can you open SQLServer and try the query there?

Do you have write access to the table?

Does the table have a different field that is the primary
key and you're not setting the value for that?

Is the record you're trying to add already there?

Robin S.
----------------------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:2d***************************@news.chello.p l...
Hi,

I'm trying to make a simple operation (insert into DB) in VB 2005
and SQL Server.

The code is as follows:

Dim sConnectionString As String = _
"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirec tory|\DB.mdf....

Dim cnDB As New SqlConnection(sConnectionString)
cnDB.Open()
Dim strSQL As String
strSQL = "INSERT INTO Company (CompanyName) VALUES ('four')"
Dim command As SqlCommand = New SqlCommand(strSQL, cnDB)
command.ExecuteNonQuery()
cnDB.Close()

But the row is not inserted into DB and also there is no any error.

Initialy I wanted to use stored procedure but in order to make it
working I made the simplest operation - without success...

Do you have any idea what is wrong?

Regards
BR
Dec 31 '06 #8

P: n/a

b_r wrote:
Database is correct - for sure...

When I want to verify inserted row I got the following information:

A first chance exception of type 'System.InvalidCastException' occurred
in Microsoft.VisualBasic.dll
<snip>

I guess Robin actually meant:

<snip>
For Each dr As DataRow in dt.rows
Debug.print "Found CompanyName: " & dr("CompanyName")
Next dr
<snip>

HTH.

Regards,

Branco.

Dec 31 '06 #9

P: n/a
b_r
I've made some additional tests and the results are as follows:
- the record is inserted but somwhere in the memory ??? - it is not
visible in table
- before closing connection to database I can see this record (via
dataadapter and data set) - Select * From Company
- afer closing connection of course recordset disappears

It looks that this record is not finaly transited to database...but why ???
Branco Medeiros napisa?(a):
b_r wrote:
>Database is correct - for sure...

When I want to verify inserted row I got the following information:

A first chance exception of type 'System.InvalidCastException' occurred
in Microsoft.VisualBasic.dll
<snip>

I guess Robin actually meant:

<snip>
>>For Each dr As DataRow in dt.rows
Debug.print "Found CompanyName: " & dr("CompanyName")
>>Next dr
<snip>

HTH.

Regards,

Branco.
Dec 31 '06 #10

P: n/a
Thanks, Branco. I copied that from a console app that I wrote
to do testing.
Robin S.
"Branco Medeiros" <br*************@gmail.comwrote in message
news:11**********************@h40g2000cwb.googlegr oups.com...
>
b_r wrote:
>Database is correct - for sure...

When I want to verify inserted row I got the following information:

A first chance exception of type 'System.InvalidCastException'
occurred
in Microsoft.VisualBasic.dll
<snip>

I guess Robin actually meant:

<snip>
For Each dr As DataRow in dt.rows
Debug.print "Found CompanyName: " & dr("CompanyName")
Next dr
<snip>

HTH.

Regards,

Branco.

Dec 31 '06 #11

P: n/a
You're not using any kind of transactions, are you?

So the problem is that you have an insert statement
that you execute, and if you turn back around and
do a select before closing the connection, the data
is there. But after you close your connection, the
data disappears, right?

What if you then re-open the connection and once
again read for the data in your program? Does it
find it then?

Robin S.
----------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:1e***************************@news.chello.pl. ..
I've made some additional tests and the results are as follows:
- the record is inserted but somwhere in the memory ??? - it is not
visible in table
- before closing connection to database I can see this record (via
dataadapter and data set) - Select * From Company
- afer closing connection of course recordset disappears

It looks that this record is not finaly transited to database...but
why ???
Branco Medeiros napisa?(a):
>b_r wrote:
>>Database is correct - for sure...

When I want to verify inserted row I got the following information:

A first chance exception of type 'System.InvalidCastException'
occurred
in Microsoft.VisualBasic.dll
<snip>

I guess Robin actually meant:

<snip>
>>>For Each dr As DataRow in dt.rows
Debug.print "Found CompanyName: " & dr("CompanyName")
>>>Next dr
<snip>

HTH.

Regards,

Branco.

Dec 31 '06 #12

P: n/a
b_r
RobinS napisał(a):
You're not using any kind of transactions, are you?
- i'm not using any transaction
So the problem is that you have an insert statement
that you execute, and if you turn back around and
do a select before closing the connection, the data
is there. But after you close your connection, the
data disappears, right?
- yes, it is just as you wrote
What if you then re-open the connection and once
again read for the data in your program? Does it
find it then?
- after re-open the connection, there is no expected record
>
Robin S.
----------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:1e***************************@news.chello.pl. ..
>I've made some additional tests and the results are as follows:
- the record is inserted but somwhere in the memory ??? - it is not
visible in table
- before closing connection to database I can see this record (via
dataadapter and data set) - Select * From Company
- afer closing connection of course recordset disappears

It looks that this record is not finaly transited to database...but
why ???
Branco Medeiros napisa?(a):
>>b_r wrote:
Database is correct - for sure...

When I want to verify inserted row I got the following information:

A first chance exception of type 'System.InvalidCastException'
occurred
in Microsoft.VisualBasic.dll
<snip>

I guess Robin actually meant:

<snip>
For Each dr As DataRow in dt.rows
Debug.print "Found CompanyName: " & dr("CompanyName")
Next dr
<snip>

HTH.

Regards,

Branco.

Jan 1 '07 #13

P: n/a
BR,

This errors comes often in these newsgroup. There is than no key or a wrong
key declared in your database. The way you do it now, assumes that you have
used an autoidentifier key.

However I think that you have not declared any key in your database or that
company is the key.
(If it is no identifier, than you have to give the key and its value in the
Insert Statement)

I hope this helps,

Cor
"b_r" <b_r@wp'_cut_it'.plschreef in bericht
news:a4**************************@news.chello.pl.. .
RobinS napisał(a):
>You're not using any kind of transactions, are you?

- i'm not using any transaction
>So the problem is that you have an insert statement
that you execute, and if you turn back around and
do a select before closing the connection, the data
is there. But after you close your connection, the
data disappears, right?

- yes, it is just as you wrote
>What if you then re-open the connection and once
again read for the data in your program? Does it
find it then?

- after re-open the connection, there is no expected record
>>
Robin S.
----------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:1e***************************@news.chello.pl ...
>>I've made some additional tests and the results are as follows:
- the record is inserted but somwhere in the memory ??? - it is not
visible in table
- before closing connection to database I can see this record (via
dataadapter and data set) - Select * From Company
- afer closing connection of course recordset disappears

It looks that this record is not finaly transited to database...but why
???
Branco Medeiros napisa?(a):
b_r wrote:
Database is correct - for sure...
>
When I want to verify inserted row I got the following information:
>
A first chance exception of type 'System.InvalidCastException'
occurred
in Microsoft.VisualBasic.dll
<snip>

I guess Robin actually meant:

<snip>
>For Each dr As DataRow in dt.rows
Debug.print "Found CompanyName: " & dr("CompanyName")
>Next dr
<snip>

HTH.

Regards,

Branco.
Jan 1 '07 #14

P: n/a
I asked him a few posts ago if he was filling a primary key and he
didn't answer, so this is a good question to ask.

So does your table have a primary key defined? What field is it?
Are you filling it with your Insert statement?

Robin S.
-------------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...
BR,

This errors comes often in these newsgroup. There is than no key or a
wrong key declared in your database. The way you do it now, assumes
that you have used an autoidentifier key.

However I think that you have not declared any key in your database or
that company is the key.
(If it is no identifier, than you have to give the key and its value
in the Insert Statement)

I hope this helps,

Cor
"b_r" <b_r@wp'_cut_it'.plschreef in bericht
news:a4**************************@news.chello.pl.. .
>RobinS napisał(a):
>>You're not using any kind of transactions, are you?

- i'm not using any transaction
>>So the problem is that you have an insert statement
that you execute, and if you turn back around and
do a select before closing the connection, the data
is there. But after you close your connection, the
data disappears, right?

- yes, it is just as you wrote
>>What if you then re-open the connection and once
again read for the data in your program? Does it
find it then?

- after re-open the connection, there is no expected record
>>>
Robin S.
----------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:1e***************************@news.chello.p l...
I've made some additional tests and the results are as follows:
- the record is inserted but somwhere in the memory ??? - it is not
visible in table
- before closing connection to database I can see this record (via
dataadapter and data set) - Select * From Company
- afer closing connection of course recordset disappears

It looks that this record is not finaly transited to database...but
why ???
Branco Medeiros napisa?(a):
b_r wrote:
>Database is correct - for sure...
>>
>When I want to verify inserted row I got the following
>information:
>>
>A first chance exception of type 'System.InvalidCastException'
>occurred
>in Microsoft.VisualBasic.dll
<snip>
>
I guess Robin actually meant:
>
<snip>
>>For Each dr As DataRow in dt.rows
Debug.print "Found CompanyName: " & dr("CompanyName")
>>Next dr
<snip>
>
HTH.
>
Regards,
>
Branco.
>

Jan 1 '07 #15

P: n/a
b_r
Yes, of course there is primary key.
Initialy there was only one field "CompanyName" which was also set as
primary key - in order to simplify databse as much as possible.

I made a lof of tests and now I have table:
Column Name DataType
ID int
CompanyName nvarchar(50)

where
Columns - ID (ASC)
Is Unique - Yes
Type - Primary Key

and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES (5,'four')"

Everything looks ok but record is not inserted to database. As I wrote
before there is something strange because before closing connection to
DB I can see this record (select *...) from VB level but directly in
database it doesn't exist.

RobinS napisał(a):
I asked him a few posts ago if he was filling a primary key and he
didn't answer, so this is a good question to ask.

So does your table have a primary key defined? What field is it?
Are you filling it with your Insert statement?

Robin S.
-------------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...
>BR,

This errors comes often in these newsgroup. There is than no key or a
wrong key declared in your database. The way you do it now, assumes
that you have used an autoidentifier key.

However I think that you have not declared any key in your database or
that company is the key.
(If it is no identifier, than you have to give the key and its value
in the Insert Statement)

I hope this helps,

Cor
"b_r" <b_r@wp'_cut_it'.plschreef in bericht
news:a4**************************@news.chello.pl. ..
>>RobinS napisał(a):
You're not using any kind of transactions, are you?
- i'm not using any transaction

So the problem is that you have an insert statement
that you execute, and if you turn back around and
do a select before closing the connection, the data
is there. But after you close your connection, the
data disappears, right?
- yes, it is just as you wrote

What if you then re-open the connection and once
again read for the data in your program? Does it
find it then?
- after re-open the connection, there is no expected record

Robin S.
----------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:1e***************************@news.chello. pl...
I've made some additional tests and the results are as follows:
- the record is inserted but somwhere in the memory ??? - it is not
visible in table
- before closing connection to database I can see this record (via
dataadapter and data set) - Select * From Company
- afer closing connection of course recordset disappears
>
It looks that this record is not finaly transited to database...but
why ???
>
>
Branco Medeiros napisa?(a):
>b_r wrote:
>>Database is correct - for sure...
>>>
>>When I want to verify inserted row I got the following
>>information:
>>>
>>A first chance exception of type 'System.InvalidCastException'
>>occurred
>>in Microsoft.VisualBasic.dll
><snip>
>>
>I guess Robin actually meant:
>>
><snip>
>>>For Each dr As DataRow in dt.rows
> Debug.print "Found CompanyName: " & dr("CompanyName")
>>>Next dr
><snip>
>>
>HTH.
>>
>Regards,
>>
>Branco.
>>

Jan 2 '07 #16

P: n/a
I note that in your connection you are using the |DataDirectory| macro.

Are you absolutely that the expansion of the |DataDirectory| macro results
in what you think you should.

You can find out by including a line at a point where the database is
'open':

Console.WriteLine(AppDomain.CurrentDomain.GetData( "DataDirectory"))

What it resolves to will suspend on how the application is deployed.

I strongly suspect is that the result of this test will indicate thet the
database being updated is different to what you think.
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:32**************************@news.chello.pl.. .
Yes, of course there is primary key.
Initialy there was only one field "CompanyName" which was also set as
primary key - in order to simplify databse as much as possible.

I made a lof of tests and now I have table:
Column Name DataType
ID int
CompanyName nvarchar(50)

where
Columns - ID (ASC)
Is Unique - Yes
Type - Primary Key

and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES (5,'four')"

Everything looks ok but record is not inserted to database. As I wrote
before there is something strange because before closing connection to DB
I can see this record (select *...) from VB level but directly in database
it doesn't exist.

RobinS napisał(a):
>I asked him a few posts ago if he was filling a primary key and he
didn't answer, so this is a good question to ask.

So does your table have a primary key defined? What field is it?
Are you filling it with your Insert statement?

Robin S.
-------------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...
>>BR,

This errors comes often in these newsgroup. There is than no key or a
wrong key declared in your database. The way you do it now, assumes that
you have used an autoidentifier key.

However I think that you have not declared any key in your database or
that company is the key.
(If it is no identifier, than you have to give the key and its value in
the Insert Statement)

I hope this helps,

Cor
"b_r" <b_r@wp'_cut_it'.plschreef in bericht
news:a4**************************@news.chello.pl ...
RobinS napisał(a):
You're not using any kind of transactions, are you?
- i'm not using any transaction

So the problem is that you have an insert statement
that you execute, and if you turn back around and
do a select before closing the connection, the data
is there. But after you close your connection, the
data disappears, right?
- yes, it is just as you wrote

What if you then re-open the connection and once
again read for the data in your program? Does it
find it then?
- after re-open the connection, there is no expected record

Robin S.
----------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:1e***************************@news.chello .pl...
>I've made some additional tests and the results are as follows:
>- the record is inserted but somwhere in the memory ??? - it is not
>visible in table
>- before closing connection to database I can see this record (via
>dataadapter and data set) - Select * From Company
>- afer closing connection of course recordset disappears
>>
>It looks that this record is not finaly transited to database...but
>why ???
>>
>>
>Branco Medeiros napisa?(a):
>>b_r wrote:
>>>Database is correct - for sure...
>>>>
>>>When I want to verify inserted row I got the following information:
>>>>
>>>A first chance exception of type 'System.InvalidCastException'
>>>occurred
>>>in Microsoft.VisualBasic.dll
>><snip>
>>>
>>I guess Robin actually meant:
>>>
>><snip>
>>>>For Each dr As DataRow in dt.rows
>> Debug.print "Found CompanyName: " & dr("CompanyName")
>>>>Next dr
>><snip>
>>>
>>HTH.
>>>
>>Regards,
>>>
>>Branco.
>>>
Jan 2 '07 #17

P: n/a
That's what I thought originally. There's just no way you could
write it, be able to read it back, and then it's not there.
So either he's writing to a different database, or he's somehow
doing transactions, and he's doing a rollback instead of a
commit (he said he is not doing transactions).

But I asked him to *close* the connection and *reopen* it and
read the data back, and he says he did that and it's not there.
Assuming he used the same connection string and everything,
it would open the same database it wrote the record to,
and should find the record. Right?

Unless he didn't really do what I recommended, and just said
he did because he didn't believe it would tell him anything.
*GASP* Surely not.

Robin S.
--------------------------------------
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I note that in your connection you are using the |DataDirectory| macro.

Are you absolutely that the expansion of the |DataDirectory| macro
results in what you think you should.

You can find out by including a line at a point where the database is
'open':

Console.WriteLine(AppDomain.CurrentDomain.GetData( "DataDirectory"))

What it resolves to will suspend on how the application is deployed.

I strongly suspect is that the result of this test will indicate thet
the database being updated is different to what you think.
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:32**************************@news.chello.pl.. .
>Yes, of course there is primary key.
Initialy there was only one field "CompanyName" which was also set as
primary key - in order to simplify databse as much as possible.

I made a lof of tests and now I have table:
Column Name DataType
ID int
CompanyName nvarchar(50)

where
Columns - ID (ASC)
Is Unique - Yes
Type - Primary Key

and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES
(5,'four')"

Everything looks ok but record is not inserted to database. As I
wrote before there is something strange because before closing
connection to DB I can see this record (select *...) from VB level
but directly in database it doesn't exist.

RobinS napisał(a):
>>I asked him a few posts ago if he was filling a primary key and he
didn't answer, so this is a good question to ask.

So does your table have a primary key defined? What field is it?
Are you filling it with your Insert statement?

Robin S.
-------------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...
BR,

This errors comes often in these newsgroup. There is than no key or
a wrong key declared in your database. The way you do it now,
assumes that you have used an autoidentifier key.

However I think that you have not declared any key in your database
or that company is the key.
(If it is no identifier, than you have to give the key and its
value in the Insert Statement)

I hope this helps,

Cor
"b_r" <b_r@wp'_cut_it'.plschreef in bericht
news:a4**************************@news.chello.p l...
RobinS napisał(a):
>You're not using any kind of transactions, are you?
- i'm not using any transaction
>
>So the problem is that you have an insert statement
>that you execute, and if you turn back around and
>do a select before closing the connection, the data
>is there. But after you close your connection, the
>data disappears, right?
- yes, it is just as you wrote
>
>What if you then re-open the connection and once
>again read for the data in your program? Does it
>find it then?
- after re-open the connection, there is no expected record
>
>Robin S.
>----------------------------
>"b_r" <b_r@wp'_cut_it'.plwrote in message
>news:1e***************************@news.chell o.pl...
>>I've made some additional tests and the results are as follows:
>>- the record is inserted but somwhere in the memory ??? - it is
>>not visible in table
>>- before closing connection to database I can see this record
>>(via dataadapter and data set) - Select * From Company
>>- afer closing connection of course recordset disappears
>>>
>>It looks that this record is not finaly transited to
>>database...but why ???
>>>
>>>
>>Branco Medeiros napisa?(a):
>>>b_r wrote:
>>>>Database is correct - for sure...
>>>>>
>>>>When I want to verify inserted row I got the following
>>>>information:
>>>>>
>>>>A first chance exception of type 'System.InvalidCastException'
>>>>occurred
>>>>in Microsoft.VisualBasic.dll
>>><snip>
>>>>
>>>I guess Robin actually meant:
>>>>
>>><snip>
>>>>>For Each dr As DataRow in dt.rows
>>> Debug.print "Found CompanyName: " & dr("CompanyName")
>>>>>Next dr
>>><snip>
>>>>
>>>HTH.
>>>>
>>>Regards,
>>>>
>>>Branco.
>>>>

Jan 2 '07 #18

P: n/a
b_r
I used the following statement:
Debug.Print(AppDomain.CurrentDomain.GetData("DataD irectory")) - but it
shows nothing...???

In order to verify if I connect to right database I modified Column Name
in INSERT statement (different than in database) and of course error
appeared - maybe the way is not so "beautiful" but it gives results.

We are still talking about connectivity to wrong database what in my
opinion is correct.

Thank you guys for help but there is no sense to continue this topic -
as we can see even if problem seems simple - the solution isn't...

Regards
BR

RobinS napisał(a):
That's what I thought originally. There's just no way you could
write it, be able to read it back, and then it's not there.
So either he's writing to a different database, or he's somehow
doing transactions, and he's doing a rollback instead of a
commit (he said he is not doing transactions).

But I asked him to *close* the connection and *reopen* it and
read the data back, and he says he did that and it's not there.
Assuming he used the same connection string and everything,
it would open the same database it wrote the record to,
and should find the record. Right?

Unless he didn't really do what I recommended, and just said
he did because he didn't believe it would tell him anything.
*GASP* Surely not.

Robin S.
--------------------------------------
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I note that in your connection you are using the |DataDirectory| macro.

Are you absolutely that the expansion of the |DataDirectory| macro
results in what you think you should.

You can find out by including a line at a point where the database is
'open':

Console.WriteLine(AppDomain.CurrentDomain.GetData( "DataDirectory"))

What it resolves to will suspend on how the application is deployed.

I strongly suspect is that the result of this test will indicate thet
the database being updated is different to what you think.
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:32**************************@news.chello.pl. ..
>>Yes, of course there is primary key.
Initialy there was only one field "CompanyName" which was also set as
primary key - in order to simplify databse as much as possible.

I made a lof of tests and now I have table:
Column Name DataType
ID int
CompanyName nvarchar(50)

where
Columns - ID (ASC)
Is Unique - Yes
Type - Primary Key

and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES
(5,'four')"

Everything looks ok but record is not inserted to database. As I
wrote before there is something strange because before closing
connection to DB I can see this record (select *...) from VB level
but directly in database it doesn't exist.

RobinS napisał(a):
I asked him a few posts ago if he was filling a primary key and he
didn't answer, so this is a good question to ask.

So does your table have a primary key defined? What field is it?
Are you filling it with your Insert statement?

Robin S.
-------------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...
BR,
>
This errors comes often in these newsgroup. There is than no key or
a wrong key declared in your database. The way you do it now,
assumes that you have used an autoidentifier key.
>
However I think that you have not declared any key in your database
or that company is the key.
(If it is no identifier, than you have to give the key and its
value in the Insert Statement)
>
I hope this helps,
>
Cor
>
>
"b_r" <b_r@wp'_cut_it'.plschreef in bericht
news:a4**************************@news.chello. pl...
>RobinS napisał(a):
>>You're not using any kind of transactions, are you?
>- i'm not using any transaction
>>
>>So the problem is that you have an insert statement
>>that you execute, and if you turn back around and
>>do a select before closing the connection, the data
>>is there. But after you close your connection, the
>>data disappears, right?
>- yes, it is just as you wrote
>>
>>What if you then re-open the connection and once
>>again read for the data in your program? Does it
>>find it then?
>- after re-open the connection, there is no expected record
>>
>>Robin S.
>>----------------------------
>>"b_r" <b_r@wp'_cut_it'.plwrote in message
>>news:1e***************************@news.chel lo.pl...
>>>I've made some additional tests and the results are as follows:
>>>- the record is inserted but somwhere in the memory ??? - it is
>>>not visible in table
>>>- before closing connection to database I can see this record
>>>(via dataadapter and data set) - Select * From Company
>>>- afer closing connection of course recordset disappears
>>>>
>>>It looks that this record is not finaly transited to
>>>database...but why ???
>>>>
>>>>
>>>Branco Medeiros napisa?(a):
>>>>b_r wrote:
>>>>>Database is correct - for sure...
>>>>>>
>>>>>When I want to verify inserted row I got the following
>>>>>information:
>>>>>>
>>>>>A first chance exception of type 'System.InvalidCastException'
>>>>>occurred
>>>>>in Microsoft.VisualBasic.dll
>>>><snip>
>>>>>
>>>>I guess Robin actually meant:
>>>>>
>>>><snip>
>>>>>>For Each dr As DataRow in dt.rows
>>>> Debug.print "Found CompanyName: " & dr("CompanyName")
>>>>>>Next dr
>>>><snip>
>>>>>
>>>>HTH.
>>>>>
>>>>Regards,
>>>>>
>>>>Branco.
>>>>>

Jan 2 '07 #19

P: n/a
If AppDomain.CurrentDomain.GetData("DataDirectory") does not retuen anything
then that means that it is not set.

In this case, the 'connection' will be using the DB.mdf that is in the same
directory as the executable you are running.

Is this the database that you expect it to be using?
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:cb***************************@news.chello.pl. ..
>I used the following statement:
Debug.Print(AppDomain.CurrentDomain.GetData("DataD irectory")) - but it
shows nothing...???

In order to verify if I connect to right database I modified Column Name
in INSERT statement (different than in database) and of course error
appeared - maybe the way is not so "beautiful" but it gives results.

We are still talking about connectivity to wrong database what in my
opinion is correct.

Thank you guys for help but there is no sense to continue this topic - as
we can see even if problem seems simple - the solution isn't...

Regards
BR

RobinS napisał(a):
>That's what I thought originally. There's just no way you could
write it, be able to read it back, and then it's not there.
So either he's writing to a different database, or he's somehow
doing transactions, and he's doing a rollback instead of a
commit (he said he is not doing transactions).

But I asked him to *close* the connection and *reopen* it and
read the data back, and he says he did that and it's not there.
Assuming he used the same connection string and everything,
it would open the same database it wrote the record to,
and should find the record. Right?

Unless he didn't really do what I recommended, and just said
he did because he didn't believe it would tell him anything.
*GASP* Surely not.

Robin S.
--------------------------------------
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>I note that in your connection you are using the |DataDirectory| macro.

Are you absolutely that the expansion of the |DataDirectory| macro
results in what you think you should.

You can find out by including a line at a point where the database is
'open':

Console.WriteLine(AppDomain.CurrentDomain.GetData( "DataDirectory"))

What it resolves to will suspend on how the application is deployed.

I strongly suspect is that the result of this test will indicate thet
the database being updated is different to what you think.
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:32**************************@news.chello.pl ...
Yes, of course there is primary key.
Initialy there was only one field "CompanyName" which was also set as
primary key - in order to simplify databse as much as possible.

I made a lof of tests and now I have table:
Column Name DataType
ID int
CompanyName nvarchar(50)

where
Columns - ID (ASC)
Is Unique - Yes
Type - Primary Key

and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES (5,'four')"

Everything looks ok but record is not inserted to database. As I wrote
before there is something strange because before closing connection to
DB I can see this record (select *...) from VB level but directly in
database it doesn't exist.

RobinS napisał(a):
I asked him a few posts ago if he was filling a primary key and he
didn't answer, so this is a good question to ask.
>
So does your table have a primary key defined? What field is it?
Are you filling it with your Insert statement?
>
Robin S.
-------------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl.. .
>BR,
>>
>This errors comes often in these newsgroup. There is than no key or a
>wrong key declared in your database. The way you do it now, assumes
>that you have used an autoidentifier key.
>>
>However I think that you have not declared any key in your database
>or that company is the key.
>(If it is no identifier, than you have to give the key and its value
>in the Insert Statement)
>>
>I hope this helps,
>>
>Cor
>>
>>
>"b_r" <b_r@wp'_cut_it'.plschreef in bericht
>news:a4**************************@news.chello .pl...
>>RobinS napisał(a):
>>>You're not using any kind of transactions, are you?
>>- i'm not using any transaction
>>>
>>>So the problem is that you have an insert statement
>>>that you execute, and if you turn back around and
>>>do a select before closing the connection, the data
>>>is there. But after you close your connection, the
>>>data disappears, right?
>>- yes, it is just as you wrote
>>>
>>>What if you then re-open the connection and once
>>>again read for the data in your program? Does it
>>>find it then?
>>- after re-open the connection, there is no expected record
>>>
>>>Robin S.
>>>----------------------------
>>>"b_r" <b_r@wp'_cut_it'.plwrote in message
>>>news:1e***************************@news.che llo.pl...
>>>>I've made some additional tests and the results are as follows:
>>>>- the record is inserted but somwhere in the memory ??? - it is
>>>>not visible in table
>>>>- before closing connection to database I can see this record (via
>>>>dataadapter and data set) - Select * From Company
>>>>- afer closing connection of course recordset disappears
>>>>>
>>>>It looks that this record is not finaly transited to
>>>>database...but why ???
>>>>>
>>>>>
>>>>Branco Medeiros napisa?(a):
>>>>>b_r wrote:
>>>>>>Database is correct - for sure...
>>>>>>>
>>>>>>When I want to verify inserted row I got the following
>>>>>>information:
>>>>>>>
>>>>>>A first chance exception of type 'System.InvalidCastException'
>>>>>>occurred
>>>>>>in Microsoft.VisualBasic.dll
>>>>><snip>
>>>>>>
>>>>>I guess Robin actually meant:
>>>>>>
>>>>><snip>
>>>>>>>For Each dr As DataRow in dt.rows
>>>>> Debug.print "Found CompanyName: " & dr("CompanyName")
>>>>>>>Next dr
>>>>><snip>
>>>>>>
>>>>>HTH.
>>>>>>
>>>>>Regards,
>>>>>>
>>>>>Branco.
>>>>>>
Jan 2 '07 #20

P: n/a
Also, did you try closing your connection, then
re-opening it and re-querying your database for that
record you think you just added? If this works,
and it finds it, then you are indeed using a different
database from the one you think you are using.

If it doesn't work, it's a different problem.

Robin S.
------------------------------
"Stephany Young" <noone@localhostwrote in message
news:O%***************@TK2MSFTNGP04.phx.gbl...
If AppDomain.CurrentDomain.GetData("DataDirectory") does not retuen
anything then that means that it is not set.

In this case, the 'connection' will be using the DB.mdf that is in the
same directory as the executable you are running.

Is this the database that you expect it to be using?
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:cb***************************@news.chello.pl. ..
>>I used the following statement:
Debug.Print(AppDomain.CurrentDomain.GetData("Data Directory")) - but
it shows nothing...???

In order to verify if I connect to right database I modified Column
Name in INSERT statement (different than in database) and of course
error appeared - maybe the way is not so "beautiful" but it gives
results.

We are still talking about connectivity to wrong database what in my
opinion is correct.

Thank you guys for help but there is no sense to continue this
topic - as we can see even if problem seems simple - the solution
isn't...

Regards
BR

RobinS napisał(a):
>>That's what I thought originally. There's just no way you could
write it, be able to read it back, and then it's not there.
So either he's writing to a different database, or he's somehow
doing transactions, and he's doing a rollback instead of a
commit (he said he is not doing transactions).

But I asked him to *close* the connection and *reopen* it and
read the data back, and he says he did that and it's not there.
Assuming he used the same connection string and everything,
it would open the same database it wrote the record to,
and should find the record. Right?

Unless he didn't really do what I recommended, and just said
he did because he didn't believe it would tell him anything.
*GASP* Surely not.

Robin S.
--------------------------------------
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl.. .
I note that in your connection you are using the |DataDirectory|
macro.

Are you absolutely that the expansion of the |DataDirectory| macro
results in what you think you should.

You can find out by including a line at a point where the database
is 'open':
Console.WriteLine(AppDomain.CurrentDomain.GetDa ta("DataDirectory"))

What it resolves to will suspend on how the application is
deployed.

I strongly suspect is that the result of this test will indicate
thet the database being updated is different to what you think.
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:32**************************@news.chello.p l...
Yes, of course there is primary key.
Initialy there was only one field "CompanyName" which was also set
as primary key - in order to simplify databse as much as possible.
>
I made a lof of tests and now I have table:
Column Name DataType
ID int
CompanyName nvarchar(50)
>
where
Columns - ID (ASC)
Is Unique - Yes
Type - Primary Key
>
and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES
(5,'four')"
>
Everything looks ok but record is not inserted to database. As I
wrote before there is something strange because before closing
connection to DB I can see this record (select *...) from VB level
but directly in database it doesn't exist.
>
>
>
RobinS napisał(a):
>I asked him a few posts ago if he was filling a primary key and
>he
>didn't answer, so this is a good question to ask.
>>
>So does your table have a primary key defined? What field is it?
>Are you filling it with your Insert statement?
>>
>Robin S.
>-------------------------
>"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
>news:eT**************@TK2MSFTNGP03.phx.gbl. ..
>>BR,
>>>
>>This errors comes often in these newsgroup. There is than no key
>>or a wrong key declared in your database. The way you do it now,
>>assumes that you have used an autoidentifier key.
>>>
>>However I think that you have not declared any key in your
>>database or that company is the key.
>>(If it is no identifier, than you have to give the key and its
>>value in the Insert Statement)
>>>
>>I hope this helps,
>>>
>>Cor
>>>
>>>
>>"b_r" <b_r@wp'_cut_it'.plschreef in bericht
>>news:a4**************************@news.chell o.pl...
>>>RobinS napisał(a):
>>>>You're not using any kind of transactions, are you?
>>>- i'm not using any transaction
>>>>
>>>>So the problem is that you have an insert statement
>>>>that you execute, and if you turn back around and
>>>>do a select before closing the connection, the data
>>>>is there. But after you close your connection, the
>>>>data disappears, right?
>>>- yes, it is just as you wrote
>>>>
>>>>What if you then re-open the connection and once
>>>>again read for the data in your program? Does it
>>>>find it then?
>>>- after re-open the connection, there is no expected record
>>>>
>>>>Robin S.
>>>>----------------------------
>>>>"b_r" <b_r@wp'_cut_it'.plwrote in message
>>>>news:1e***************************@news.ch ello.pl...
>>>>>I've made some additional tests and the results are as
>>>>>follows:
>>>>>- the record is inserted but somwhere in the memory ??? - it
>>>>>is not visible in table
>>>>>- before closing connection to database I can see this record
>>>>>(via dataadapter and data set) - Select * From Company
>>>>>- afer closing connection of course recordset disappears
>>>>>>
>>>>>It looks that this record is not finaly transited to
>>>>>database...but why ???
>>>>>>
>>>>>>
>>>>>Branco Medeiros napisa?(a):
>>>>>>b_r wrote:
>>>>>>>Database is correct - for sure...
>>>>>>>>
>>>>>>>When I want to verify inserted row I got the following
>>>>>>>information:
>>>>>>>>
>>>>>>>A first chance exception of type
>>>>>>>'System.InvalidCastException' occurred
>>>>>>>in Microsoft.VisualBasic.dll
>>>>>><snip>
>>>>>>>
>>>>>>I guess Robin actually meant:
>>>>>>>
>>>>>><snip>
>>>>>>>>For Each dr As DataRow in dt.rows
>>>>>> Debug.print "Found CompanyName: " & dr("CompanyName")
>>>>>>>>Next dr
>>>>>><snip>
>>>>>>>
>>>>>>HTH.
>>>>>>>
>>>>>>Regards,
>>>>>>>
>>>>>>Branco.
>>>>>>>

Jan 3 '07 #21

P: n/a
b_r
Stephany,
yes, the database is in the same directoy as the executable.

Robin,
yes I tried as you suggest and after reopening the record is not found.
Your suspicion is that there is another database... but in this
situation additional database should have the same structure like
database dedicated for the project (there is no error during insert
isnruction execution)... so how it is possible that identical database
is created, automatically or any other way???

The best way to verify my project is the possiblity to send files to
someone who has the same environment (VB2005 Eexpress, SQL Express) and
run it.

RobinS napisał(a):
Also, did you try closing your connection, then
re-opening it and re-querying your database for that
record you think you just added? If this works,
and it finds it, then you are indeed using a different
database from the one you think you are using.

If it doesn't work, it's a different problem.

Robin S.
------------------------------
"Stephany Young" <noone@localhostwrote in message
news:O%***************@TK2MSFTNGP04.phx.gbl...
>If AppDomain.CurrentDomain.GetData("DataDirectory") does not retuen
anything then that means that it is not set.

In this case, the 'connection' will be using the DB.mdf that is in the
same directory as the executable you are running.

Is this the database that you expect it to be using?
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:cb***************************@news.chello.pl ...
>>I used the following statement:
Debug.Print(AppDomain.CurrentDomain.GetData("Dat aDirectory")) - but
it shows nothing...???

In order to verify if I connect to right database I modified Column
Name in INSERT statement (different than in database) and of course
error appeared - maybe the way is not so "beautiful" but it gives
results.

We are still talking about connectivity to wrong database what in my
opinion is correct.

Thank you guys for help but there is no sense to continue this
topic - as we can see even if problem seems simple - the solution
isn't...

Regards
BR

RobinS napisał(a):
That's what I thought originally. There's just no way you could
write it, be able to read it back, and then it's not there.
So either he's writing to a different database, or he's somehow
doing transactions, and he's doing a rollback instead of a
commit (he said he is not doing transactions).

But I asked him to *close* the connection and *reopen* it and
read the data back, and he says he did that and it's not there.
Assuming he used the same connection string and everything,
it would open the same database it wrote the record to,
and should find the record. Right?

Unless he didn't really do what I recommended, and just said
he did because he didn't believe it would tell him anything.
*GASP* Surely not.

Robin S.
--------------------------------------
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl. ..
I note that in your connection you are using the |DataDirectory|
macro.
>
Are you absolutely that the expansion of the |DataDirectory| macro
results in what you think you should.
>
You can find out by including a line at a point where the database
is 'open':
>
>
Console.WriteLine(AppDomain.CurrentDomain.GetD ata("DataDirectory"))
>
What it resolves to will suspend on how the application is
deployed.
>
I strongly suspect is that the result of this test will indicate
thet the database being updated is different to what you think.
>
>
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:32**************************@news.chello. pl...
>Yes, of course there is primary key.
>Initialy there was only one field "CompanyName" which was also set
>as primary key - in order to simplify databse as much as possible.
>>
>I made a lof of tests and now I have table:
>Column Name DataType
>ID int
>CompanyName nvarchar(50)
>>
>where
>Columns - ID (ASC)
>Is Unique - Yes
>Type - Primary Key
>>
>and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES
>(5,'four')"
>>
>Everything looks ok but record is not inserted to database. As I
>wrote before there is something strange because before closing
>connection to DB I can see this record (select *...) from VB level
>but directly in database it doesn't exist.
>>
>>
>>
>RobinS napisał(a):
>>I asked him a few posts ago if he was filling a primary key and
>>he
>>didn't answer, so this is a good question to ask.
>>>
>>So does your table have a primary key defined? What field is it?
>>Are you filling it with your Insert statement?
>>>
>>Robin S.
>>-------------------------
>>"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
>>news:eT**************@TK2MSFTNGP03.phx.gbl.. .
>>>BR,
>>>>
>>>This errors comes often in these newsgroup. There is than no key
>>>or a wrong key declared in your database. The way you do it now,
>>>assumes that you have used an autoidentifier key.
>>>>
>>>However I think that you have not declared any key in your
>>>database or that company is the key.
>>>(If it is no identifier, than you have to give the key and its
>>>value in the Insert Statement)
>>>>
>>>I hope this helps,
>>>>
>>>Cor
>>>>
>>>>
>>>"b_r" <b_r@wp'_cut_it'.plschreef in bericht
>>>news:a4**************************@news.chel lo.pl...
>>>>RobinS napisał(a):
>>>>>You're not using any kind of transactions, are you?
>>>>- i'm not using any transaction
>>>>>
>>>>>So the problem is that you have an insert statement
>>>>>that you execute, and if you turn back around and
>>>>>do a select before closing the connection, the data
>>>>>is there. But after you close your connection, the
>>>>>data disappears, right?
>>>>- yes, it is just as you wrote
>>>>>
>>>>>What if you then re-open the connection and once
>>>>>again read for the data in your program? Does it
>>>>>find it then?
>>>>- after re-open the connection, there is no expected record
>>>>>
>>>>>Robin S.
>>>>>----------------------------
>>>>>"b_r" <b_r@wp'_cut_it'.plwrote in message
>>>>>news:1e***************************@news.c hello.pl...
>>>>>>I've made some additional tests and the results are as
>>>>>>follows:
>>>>>>- the record is inserted but somwhere in the memory ??? - it
>>>>>>is not visible in table
>>>>>>- before closing connection to database I can see this record
>>>>>>(via dataadapter and data set) - Select * From Company
>>>>>>- afer closing connection of course recordset disappears
>>>>>>>
>>>>>>It looks that this record is not finaly transited to
>>>>>>database...but why ???
>>>>>>>
>>>>>>>
>>>>>>Branco Medeiros napisa?(a):
>>>>>>>b_r wrote:
>>>>>>>>Database is correct - for sure...
>>>>>>>>>
>>>>>>>>When I want to verify inserted row I got the following
>>>>>>>>information:
>>>>>>>>>
>>>>>>>>A first chance exception of type
>>>>>>>>'System.InvalidCastException' occurred
>>>>>>>>in Microsoft.VisualBasic.dll
>>>>>>><snip>
>>>>>>>>
>>>>>>>I guess Robin actually meant:
>>>>>>>>
>>>>>>><snip>
>>>>>>>>>For Each dr As DataRow in dt.rows
>>>>>>> Debug.print "Found CompanyName: " & dr("CompanyName")
>>>>>>>>>Next dr
>>>>>>><snip>
>>>>>>>>
>>>>>>>HTH.
>>>>>>>>
>>>>>>>Regards,
>>>>>>>>
>>>>>>>Branco.
>>>>>>>>

Jan 3 '07 #22

P: n/a
Okay, I looked at this guy's code. It works with VS2005 and SQLServer.
So I think
it's a problem with his SQLServerExpress setup. Could the problem be
caused
by not having remote connections enabled or not having update access to
the
database or something like that? Would not having remote connections
enabled
also keep him from reading the database (I think so) ?

I've sent him back some code to try that will do what I recommended just
to
try it (with closing/opening connection and re-reading). If that
displays the
fact that the record is, in fact, not being added to the database
(which, I
suspect is the case), then it's a problem with his connection or his
database
or something like that.

Other opinions are welcome.

Robin S.
------------------------
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:a0**************************@news.chello.pl.. .
Stephany,
yes, the database is in the same directoy as the executable.

Robin,
yes I tried as you suggest and after reopening the record is not
found.
Your suspicion is that there is another database... but in this
situation additional database should have the same structure like
database dedicated for the project (there is no error during insert
isnruction execution)... so how it is possible that identical database
is created, automatically or any other way???

The best way to verify my project is the possiblity to send files to
someone who has the same environment (VB2005 Eexpress, SQL Express)
and run it.

RobinS napisał(a):
>Also, did you try closing your connection, then
re-opening it and re-querying your database for that
record you think you just added? If this works,
and it finds it, then you are indeed using a different
database from the one you think you are using.

If it doesn't work, it's a different problem.

Robin S.
------------------------------
"Stephany Young" <noone@localhostwrote in message
news:O%***************@TK2MSFTNGP04.phx.gbl...
>>If AppDomain.CurrentDomain.GetData("DataDirectory") does not retuen
anything then that means that it is not set.

In this case, the 'connection' will be using the DB.mdf that is in
the same directory as the executable you are running.

Is this the database that you expect it to be using?
"b_r" <b_r@wp'_cut_it'.plwrote in message
news:cb***************************@news.chello.p l...
I used the following statement:
Debug.Print(AppDomain.CurrentDomain.GetData("Da taDirectory")) - but
it shows nothing...???

In order to verify if I connect to right database I modified Column
Name in INSERT statement (different than in database) and of course
error appeared - maybe the way is not so "beautiful" but it gives
results.

We are still talking about connectivity to wrong database what in
my opinion is correct.

Thank you guys for help but there is no sense to continue this
topic - as we can see even if problem seems simple - the solution
isn't...

Regards
BR

RobinS napisał(a):
That's what I thought originally. There's just no way you could
write it, be able to read it back, and then it's not there.
So either he's writing to a different database, or he's somehow
doing transactions, and he's doing a rollback instead of a
commit (he said he is not doing transactions).
>
But I asked him to *close* the connection and *reopen* it and
read the data back, and he says he did that and it's not there.
Assuming he used the same connection string and everything,
it would open the same database it wrote the record to,
and should find the record. Right?
>
Unless he didn't really do what I recommended, and just said
he did because he didn't believe it would tell him anything.
*GASP* Surely not.
>
Robin S.
--------------------------------------
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl.. .
>I note that in your connection you are using the |DataDirectory|
>macro.
>>
>Are you absolutely that the expansion of the |DataDirectory|
>macro results in what you think you should.
>>
>You can find out by including a line at a point where the
>database is 'open':
>>
>>
>Console.WriteLine(AppDomain.CurrentDomain.Get Data("DataDirectory"))
>>
>What it resolves to will suspend on how the application is
>deployed.
>>
>I strongly suspect is that the result of this test will indicate
>thet the database being updated is different to what you think.
>>
>>
>"b_r" <b_r@wp'_cut_it'.plwrote in message
>news:32**************************@news.chello .pl...
>>Yes, of course there is primary key.
>>Initialy there was only one field "CompanyName" which was also
>>set as primary key - in order to simplify databse as much as
>>possible.
>>>
>>I made a lof of tests and now I have table:
>>Column Name DataType
>>ID int
>>CompanyName nvarchar(50)
>>>
>>where
>>Columns - ID (ASC)
>>Is Unique - Yes
>>Type - Primary Key
>>>
>>and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES
>>(5,'four')"
>>>
>>Everything looks ok but record is not inserted to database. As I
>>wrote before there is something strange because before closing
>>connection to DB I can see this record (select *...) from VB
>>level but directly in database it doesn't exist.
>>>
>>>
>>>
>>RobinS napisał(a):
>>>I asked him a few posts ago if he was filling a primary key and
>>>he
>>>didn't answer, so this is a good question to ask.
>>>>
>>>So does your table have a primary key defined? What field is
>>>it?
>>>Are you filling it with your Insert statement?
>>>>
>>>Robin S.
>>>-------------------------
>>>"Cor Ligthert [MVP]" <no************@planet.nlwrote in
>>>message news:eT**************@TK2MSFTNGP03.phx.gbl...
>>>>BR,
>>>>>
>>>>This errors comes often in these newsgroup. There is than no
>>>>key or a wrong key declared in your database. The way you do
>>>>it now, assumes that you have used an autoidentifier key.
>>>>>
>>>>However I think that you have not declared any key in your
>>>>database or that company is the key.
>>>>(If it is no identifier, than you have to give the key and its
>>>>value in the Insert Statement)
>>>>>
>>>>I hope this helps,
>>>>>
>>>>Cor
>>>>>
>>>>>
>>>>"b_r" <b_r@wp'_cut_it'.plschreef in bericht
>>>>news:a4**************************@news.che llo.pl...
>>>>>RobinS napisał(a):
>>>>>>You're not using any kind of transactions, are you?
>>>>>- i'm not using any transaction
>>>>>>
>>>>>>So the problem is that you have an insert statement
>>>>>>that you execute, and if you turn back around and
>>>>>>do a select before closing the connection, the data
>>>>>>is there. But after you close your connection, the
>>>>>>data disappears, right?
>>>>>- yes, it is just as you wrote
>>>>>>
>>>>>>What if you then re-open the connection and once
>>>>>>again read for the data in your program? Does it
>>>>>>find it then?
>>>>>- after re-open the connection, there is no expected record
>>>>>>
>>>>>>Robin S.
>>>>>>----------------------------
>>>>>>"b_r" <b_r@wp'_cut_it'.plwrote in message
>>>>>>news:1e***************************@news. chello.pl...
>>>>>>>I've made some additional tests and the results are as
>>>>>>>follows:
>>>>>>>- the record is inserted but somwhere in the memory ??? -
>>>>>>>it is not visible in table
>>>>>>>- before closing connection to database I can see this
>>>>>>>record (via dataadapter and data set) - Select * From
>>>>>>>Company
>>>>>>>- afer closing connection of course recordset disappears
>>>>>>>>
>>>>>>>It looks that this record is not finaly transited to
>>>>>>>database...but why ???
>>>>>>>>
>>>>>>>>
>>>>>>>Branco Medeiros napisa?(a):
>>>>>>>>b_r wrote:
>>>>>>>>>Database is correct - for sure...
>>>>>>>>>>
>>>>>>>>>When I want to verify inserted row I got the following
>>>>>>>>>information:
>>>>>>>>>>
>>>>>>>>>A first chance exception of type
>>>>>>>>>'System.InvalidCastException' occurred
>>>>>>>>>in Microsoft.VisualBasic.dll
>>>>>>>><snip>
>>>>>>>>>
>>>>>>>>I guess Robin actually meant:
>>>>>>>>>
>>>>>>>><snip>
>>>>>>>>>>For Each dr As DataRow in dt.rows
>>>>>>>> Debug.print "Found CompanyName: " & dr("CompanyName")
>>>>>>>>>>Next dr
>>>>>>>><snip>
>>>>>>>>>
>>>>>>>>HTH.
>>>>>>>>>
>>>>>>>>Regards,
>>>>>>>>>
>>>>>>>>Branco.
>>>>>>>>>
Jan 4 '07 #23

This discussion thread is closed

Replies have been disabled for this discussion.