Home All Groups Group Topic Archive Search About

ExecuteNonQuery - problem

Author
30 Dec 2006 12:11 PM
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=|DataDirectory|\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

Author
30 Dec 2006 1:32 PM
Just Me
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



Show quoteHide quote
"b_r" <b_r@wp'_cut_it'.pl> wrote in message
news:2d2b1$45965783$5390485a$28167@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=|DataDirectory|\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
>
Are all your drivers up to date? click for free checkup

Author
30 Dec 2006 2:06 PM
b_r
The ex message shows nothing (ex = nothing) and row is not inserted.



Just Me napisa³(a):
Show quoteHide quote
> 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'.pl> wrote in message
> news:2d2b1$45965783$5390485a$28167@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=|DataDirectory|\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
>>
>
>
Author
30 Dec 2006 3:33 PM
Just Me
'// Is this correct ? should it not be just CompanyName ?
Company (CompanyName)

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

Show quoteHide quote
"b_r" <b_r@wp'_cut_it'.pl> wrote in message
news:ca215$4596724d$5390485a$14325@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'.pl> wrote in message
>> news:2d2b1$45965783$5390485a$28167@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=|DataDirectory|\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
>>>
>>
Author
30 Dec 2006 9:37 PM
RobinS
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.
----------------------------------------
Show quoteHide quote
"b_r" <b_r@wp'_cut_it'.pl> wrote in message
news:2d2b1$45965783$5390485a$28167@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=|DataDirectory|\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
>
Author
30 Dec 2006 10:35 PM
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):
Show quoteHide quote
> 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'.pl> wrote in message
> news:2d2b1$45965783$5390485a$28167@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=|DataDirectory|\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
>>
>
>
Author
30 Dec 2006 11:14 PM
RobinS
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.
--------------------------------------

Show quoteHide quote
"b_r" <b_r@wp'_cut_it'.pl> wrote in message
news:dc021$4596e9cd$5390485a$9006@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'.pl> wrote in message
>> news:2d2b1$45965783$5390485a$28167@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=|DataDirectory|\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
>>>
>>
Author
31 Dec 2006 10:07 AM
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):
Show quoteHide quote
> 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'.pl> wrote in message
> news:dc021$4596e9cd$5390485a$9006@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'.pl> wrote in message
>>> news:2d2b1$45965783$5390485a$28167@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=|DataDirectory|\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
>>>>
>
Author
31 Dec 2006 3:40 PM
Branco Medeiros
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.
Author
31 Dec 2006 4:18 PM
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):
Show quoteHide quote
> 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.
>
Author
31 Dec 2006 6:01 PM
RobinS
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.
----------------------------
Show quoteHide quote
"b_r" <b_r@wp'_cut_it'.pl> wrote in message
news:1e736$4597e2c1$5390485a$12437@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.
>>
Author
1 Jan 2007 9:17 AM
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

Show quoteHide quote
>
> Robin S.
> ----------------------------
> "b_r" <b_r@wp'_cut_it'.pl> wrote in message
> news:1e736$4597e2c1$5390485a$12437@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.
>>>
>
>
Author
1 Jan 2007 10:34 AM
Cor Ligthert [MVP]
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


Show quoteHide quote
"b_r" <b_r@wp'_cut_it'.pl> schreef in bericht
news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>
>>
Author
1 Jan 2007 9:52 PM
RobinS
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.
-------------------------
Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:eTWSPAZLHHA.3552@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'.pl> schreef in bericht
> news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>>
>>>
>
Author
2 Jan 2007 12:30 PM
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):
Show quoteHide quote
> 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]" <notmyfirstn***@planet.nl> wrote in message
> news:eTWSPAZLHHA.3552@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'.pl> schreef in bericht
>> news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>>>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>>>
>
>
Author
2 Jan 2007 1:03 PM
Stephany Young
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.


Show quoteHide quote
"b_r" <b_r@wp'_cut_it'.pl> wrote in message
news:3210c$459a5087$5390485a$9299@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]" <notmyfirstn***@planet.nl> wrote in message
>> news:eTWSPAZLHHA.3552@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'.pl> schreef in bericht
>>> news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>>>>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>>>>
>>
Author
2 Jan 2007 5:44 PM
RobinS
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.
--------------------------------------
Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:%23ISsz5mLHHA.4384@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'.pl> wrote in message
> news:3210c$459a5087$5390485a$9299@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]" <notmyfirstn***@planet.nl> wrote in message
>>> news:eTWSPAZLHHA.3552@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'.pl> schreef in bericht
>>>> news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>>>>>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>>>>>
>>>
>
Author
2 Jan 2007 6:09 PM
b_r
I used the following statement:
Debug.Print(AppDomain.CurrentDomain.GetData("DataDirectory")) - 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):
Show quoteHide quote
> 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@localhost> wrote in message
> news:%23ISsz5mLHHA.4384@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'.pl> wrote in message
>> news:3210c$459a5087$5390485a$9299@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]" <notmyfirstn***@planet.nl> wrote in message
>>>> news:eTWSPAZLHHA.3552@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'.pl> schreef in bericht
>>>>> news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>>>>>>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>>>>>>
>
>
Author
2 Jan 2007 10:06 PM
Stephany Young
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?


Show quoteHide quote
"b_r" <b_r@wp'_cut_it'.pl> wrote in message
news:cb71e$459a9fda$5390485a$27234@news.chello.pl...
>I used the following statement:
> Debug.Print(AppDomain.CurrentDomain.GetData("DataDirectory")) - 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@localhost> wrote in message
>> news:%23ISsz5mLHHA.4384@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'.pl> wrote in message
>>> news:3210c$459a5087$5390485a$9299@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]" <notmyfirstn***@planet.nl> wrote in message
>>>>> news:eTWSPAZLHHA.3552@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'.pl> schreef in bericht
>>>>>> news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>>>>>>>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>>>>>>>
>>
Author
3 Jan 2007 3:41 AM
RobinS
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.
------------------------------
Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:O%23reIprLHHA.960@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'.pl> wrote in message
> news:cb71e$459a9fda$5390485a$27234@news.chello.pl...
>>I used the following statement:
>> Debug.Print(AppDomain.CurrentDomain.GetData("DataDirectory")) - 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@localhost> wrote in message
>>> news:%23ISsz5mLHHA.4384@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'.pl> wrote in message
>>>> news:3210c$459a5087$5390485a$9299@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]" <notmyfirstn***@planet.nl> wrote in message
>>>>>> news:eTWSPAZLHHA.3552@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'.pl> schreef in bericht
>>>>>>> news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>>>>>>>>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>>>>>>>>
>>>
>
Author
3 Jan 2007 11:39 AM
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):
Show quoteHide quote
> 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@localhost> wrote in message
> news:O%23reIprLHHA.960@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'.pl> wrote in message
>> news:cb71e$459a9fda$5390485a$27234@news.chello.pl...
>>> I used the following statement:
>>> Debug.Print(AppDomain.CurrentDomain.GetData("DataDirectory")) - 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@localhost> wrote in message
>>>> news:%23ISsz5mLHHA.4384@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'.pl> wrote in message
>>>>> news:3210c$459a5087$5390485a$9299@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]" <notmyfirstn***@planet.nl> wrote in message
>>>>>>> news:eTWSPAZLHHA.3552@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'.pl> schreef in bericht
>>>>>>>> news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>>>>>>>>>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>>>>>>>>>
>
>
Author
4 Jan 2007 12:17 AM
RobinS
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.
------------------------
Show quoteHide quote
"b_r" <b_r@wp'_cut_it'.pl> wrote in message
news:a076a$459b95ef$5390485a$5740@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@localhost> wrote in message
>> news:O%23reIprLHHA.960@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'.pl> wrote in message
>>> news:cb71e$459a9fda$5390485a$27234@news.chello.pl...
>>>> I used the following statement:
>>>> Debug.Print(AppDomain.CurrentDomain.GetData("DataDirectory")) - 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@localhost> wrote in message
>>>>> news:%23ISsz5mLHHA.4384@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'.pl> wrote in message
>>>>>> news:3210c$459a5087$5390485a$9299@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]" <notmyfirstn***@planet.nl> wrote in
>>>>>>>> message news:eTWSPAZLHHA.3552@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'.pl> schreef in bericht
>>>>>>>>> news:a4fb9$4598d1c6$5390485a$2142@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'.pl> wrote in message
>>>>>>>>>>> news:1e736$4597e2c1$5390485a$12437@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.
>>>>>>>>>>>>>
>>
Author
31 Dec 2006 5:58 PM
RobinS
Thanks, Branco. I copied that from a console app that I wrote
to do testing.
Robin S.
Show quoteHide quote
"Branco Medeiros" <branco.medei***@gmail.com> wrote in message
news:1167579638.440417.301010@h40g2000cwb.googlegroups.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.
>

Bookmark and Share

Post Thread options