Re: ExecuteNonQuery - problem
Yes, of course there is primary key.
Initialy there was only one field "CompanyNam e" 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):
Yes, of course there is primary key.
Initialy there was only one field "CompanyNam e" 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]" <notmyfirstname @planet.nlwrote in message
news:eTWSPAZLHH A.3552@TK2MSFTN GP03.phx.gbl...
>
>
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]" <notmyfirstname @planet.nlwrote in message
news:eTWSPAZLHH A.3552@TK2MSFTN GP03.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:a4fb9$459 8d1c6$5390485a$ 2142@news.chell o.pl...
>>
>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:a4fb9$459 8d1c6$5390485a$ 2142@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:1e736$4 597e2c1$5390485 a$12437@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
>>>>dataadapt er 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:
>>>>>>Databas e is correct - for sure...
>>>>>>>
>>>>>>When I want to verify inserted row I got the following
>>>>>>informati on:
>>>>>>>
>>>>>>A first chance exception of type 'System.Invalid CastException'
>>>>>>occurre d
>>>>>>in Microsoft.Visua lBasic.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.
>>>>>>
>>>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:1e736$4 597e2c1$5390485 a$12437@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
>>>>dataadapt er 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:
>>>>>>Databas e is correct - for sure...
>>>>>>>
>>>>>>When I want to verify inserted row I got the following
>>>>>>informati on:
>>>>>>>
>>>>>>A first chance exception of type 'System.Invalid CastException'
>>>>>>occurre d
>>>>>>in Microsoft.Visua lBasic.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.
>>>>>>
>
Comment