ExecuteNonQuery - problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • b_r

    #16
    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):
    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...
    >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...
    >>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.
    >>>>>>
    >
    >

    Comment

    • Stephany Young

      #17
      Re: ExecuteNonQuery - problem

      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.WriteLi ne(AppDomain.Cu rrentDomain.Get Data("DataDirec tory"))

      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:3210c$459a 5087$5390485a$9 299@news.chello .pl...
      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:eTWSPAZLH HA.3552@TK2MSFT NGP03.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$45 98d1c6$5390485a $2142@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:1e736$ 4597e2c1$539048 5a$12437@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
      >>>>>dataadapte r 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:
      >>>>>>>Databa se is correct - for sure...
      >>>>>>>>
      >>>>>>>When I want to verify inserted row I got the following information:
      >>>>>>>>
      >>>>>>>A first chance exception of type 'System.Invalid CastException'
      >>>>>>>occurr ed
      >>>>>>>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

      • RobinS

        #18
        Re: ExecuteNonQuery - problem

        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@localhos twrote in message
        news:%23ISsz5mL HHA.4384@TK2MSF TNGP03.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.WriteLi ne(AppDomain.Cu rrentDomain.Get Data("DataDirec tory"))
        >
        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:3210c$459a 5087$5390485a$9 299@news.chello .pl...
        >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:eTWSPAZL HHA.3552@TK2MSF TNGP03.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$4 598d1c6$5390485 a$2142@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:1e736 $4597e2c1$53904 85a$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:
        >>>>>>>>Databas e is correct - for sure...
        >>>>>>>>>
        >>>>>>>>When I want to verify inserted row I got the following
        >>>>>>>>informa tion:
        >>>>>>>>>
        >>>>>>>>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.
        >>>>>>>>
        >>>>>>>Regard s,
        >>>>>>>>
        >>>>>>>Branco .
        >>>>>>>>
        >>>
        >

        Comment

        • b_r

          #19
          Re: ExecuteNonQuery - problem

          I used the following statement:
          Debug.Print(App Domain.CurrentD omain.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@localhos twrote in message
          news:%23ISsz5mL HHA.4384@TK2MSF TNGP03.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.WriteLi ne(AppDomain.Cu rrentDomain.Get Data("DataDirec tory"))
          >>
          >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:3210c$459 a5087$5390485a$ 9299@news.chell o.pl...
          >>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:eTWSPAZ LHHA.3552@TK2MS FTNGP03.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$ 4598d1c6$539048 5a$2142@news.ch ello.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:1e73 6$4597e2c1$5390 485a$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:
          >>>>>>>>>Databa se is correct - for sure...
          >>>>>>>>>>
          >>>>>>>>>When I want to verify inserted row I got the following
          >>>>>>>>>inform ation:
          >>>>>>>>>>
          >>>>>>>>>A first chance exception of type 'System.Invalid CastException'
          >>>>>>>>>occurr ed
          >>>>>>>>>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 ")
          >>>>>>>>>>Nex t dr
          >>>>>>>><snip >
          >>>>>>>>>
          >>>>>>>>HTH.
          >>>>>>>>>
          >>>>>>>>Regards ,
          >>>>>>>>>
          >>>>>>>>Branc o.
          >>>>>>>>>
          >
          >

          Comment

          • Stephany Young

            #20
            Re: ExecuteNonQuery - problem

            If AppDomain.Curre ntDomain.GetDat a("DataDirector y") 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:cb71e$459a 9fda$5390485a$2 7234@news.chell o.pl...
            >I used the following statement:
            Debug.Print(App Domain.CurrentD omain.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@localhos twrote in message
            >news:%23ISsz5m LHHA.4384@TK2MS FTNGP03.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.WriteLi ne(AppDomain.Cu rrentDomain.Get Data("DataDirec tory"))
            >>>
            >>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:3210c$45 9a5087$5390485a $9299@news.chel lo.pl...
            >>>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
            >>>CompanyNam e 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:eTWSPA ZLHHA.3552@TK2M SFTNGP03.phx.gb l...
            >>>>>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 $4598d1c6$53904 85a$2142@news.c hello.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:1e7 36$4597e2c1$539 0485a$12437@new s.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
            >>>>>>>>dataada pter and data set) - Select * From Company
            >>>>>>>>- afer closing connection of course recordset disappears
            >>>>>>>>>
            >>>>>>>>It looks that this record is not finaly transited to
            >>>>>>>>databas e...but why ???
            >>>>>>>>>
            >>>>>>>>>
            >>>>>>>>Branc o Medeiros napisa?(a):
            >>>>>>>>>b_r wrote:
            >>>>>>>>>>Datab ase is correct - for sure...
            >>>>>>>>>>>
            >>>>>>>>>>Whe n I want to verify inserted row I got the following
            >>>>>>>>>>infor mation:
            >>>>>>>>>>>
            >>>>>>>>>>A first chance exception of type 'System.Invalid CastException'
            >>>>>>>>>>occur red
            >>>>>>>>>>in Microsoft.Visua lBasic.dll
            >>>>>>>>><sni p>
            >>>>>>>>>>
            >>>>>>>>>I guess Robin actually meant:
            >>>>>>>>>>
            >>>>>>>>><sni p>
            >>>>>>>>>>>Fo r Each dr As DataRow in dt.rows
            >>>>>>>>> Debug.print "Found CompanyName: " & dr("CompanyName ")
            >>>>>>>>>>>Ne xt dr
            >>>>>>>>><sni p>
            >>>>>>>>>>
            >>>>>>>>>HTH.
            >>>>>>>>>>
            >>>>>>>>>Regard s,
            >>>>>>>>>>
            >>>>>>>>>Branco .
            >>>>>>>>>>
            >>

            Comment

            • RobinS

              #21
              Re: ExecuteNonQuery - problem

              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@localhos twrote in message
              news:O%23reIprL HHA.960@TK2MSFT NGP04.phx.gbl.. .
              If AppDomain.Curre ntDomain.GetDat a("DataDirector y") 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:cb71e$459a 9fda$5390485a$2 7234@news.chell o.pl...
              >>I used the following statement:
              >Debug.Print(Ap pDomain.Current Domain.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@localhos twrote in message
              >>news:%23ISsz5 mLHHA.4384@TK2M SFTNGP03.phx.gb l...
              >>>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.Writ eLine(AppDomain .CurrentDomain. GetData("DataDi rectory"))
              >>>>
              >>>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:3210c$4 59a5087$5390485 a$9299@news.che llo.pl...
              >>>>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
              >>>>CompanyNa me nvarchar(50)
              >>>>>
              >>>>where
              >>>>Columns - ID (ASC)
              >>>>Is Unique - Yes
              >>>>Type - Primary Key
              >>>>>
              >>>>and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES
              >>>>(5,'four' )"
              >>>>>
              >>>>Everythin g looks ok but record is not inserted to database. As I
              >>>>wrote before there is something strange because before closing
              >>>>connectio n 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:eTWSP AZLHHA.3552@TK2 MSFTNGP03.phx.g bl...
              >>>>>>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
              >>>>>>databas e 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:a4fb 9$4598d1c6$5390 485a$2142@news. chello.pl...
              >>>>>>>RobinS napisa³(a):
              >>>>>>>>You'r e 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 736$4597e2c1$53 90485a$12437@ne ws.chello.pl...
              >>>>>>>>>I've made some additional tests and the results are as
              >>>>>>>>>follow s:
              >>>>>>>>>- 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
              >>>>>>>>>databa se...but why ???
              >>>>>>>>>>
              >>>>>>>>>>
              >>>>>>>>>Bran co Medeiros napisa?(a):
              >>>>>>>>>>b_r wrote:
              >>>>>>>>>>>Data base is correct - for sure...
              >>>>>>>>>>>>
              >>>>>>>>>>>Wh en I want to verify inserted row I got the following
              >>>>>>>>>>>info rmation:
              >>>>>>>>>>>>
              >>>>>>>>>>>A first chance exception of type
              >>>>>>>>>>>'Sys tem.InvalidCast Exception' occurred
              >>>>>>>>>>>in Microsoft.Visua lBasic.dll
              >>>>>>>>>><snip >
              >>>>>>>>>>>
              >>>>>>>>>>I guess Robin actually meant:
              >>>>>>>>>>>
              >>>>>>>>>><snip >
              >>>>>>>>>>>>F or Each dr As DataRow in dt.rows
              >>>>>>>>>> Debug.print "Found CompanyName: " & dr("CompanyName ")
              >>>>>>>>>>>>Nex t dr
              >>>>>>>>>><snip >
              >>>>>>>>>>>
              >>>>>>>>>>HTH .
              >>>>>>>>>>>
              >>>>>>>>>>Regar ds,
              >>>>>>>>>>>
              >>>>>>>>>>Branc o.
              >>>>>>>>>>>
              >>>
              >

              Comment

              • b_r

                #22
                Re: ExecuteNonQuery - problem

                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@localhos twrote in message
                news:O%23reIprL HHA.960@TK2MSFT NGP04.phx.gbl.. .
                >If AppDomain.Curre ntDomain.GetDat a("DataDirector y") 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:cb71e$459 a9fda$5390485a$ 27234@news.chel lo.pl...
                >>I used the following statement:
                >>Debug.Print(A ppDomain.Curren tDomain.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@localhos twrote in message
                >>>news:%23ISsz 5mLHHA.4384@TK2 MSFTNGP03.phx.g bl...
                >>>>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.Wri teLine(AppDomai n.CurrentDomain .GetData("DataD irectory"))
                >>>>>
                >>>>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:3210c$ 459a5087$539048 5a$9299@news.ch ello.pl...
                >>>>>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
                >>>>>CompanyNam e nvarchar(50)
                >>>>>>
                >>>>>where
                >>>>>Columns - ID (ASC)
                >>>>>Is Unique - Yes
                >>>>>Type - Primary Key
                >>>>>>
                >>>>>and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES
                >>>>>(5,'four') "
                >>>>>>
                >>>>>Everythi ng looks ok but record is not inserted to database. As I
                >>>>>wrote before there is something strange because before closing
                >>>>>connecti on 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:eTWS PAZLHHA.3552@TK 2MSFTNGP03.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,
                >>>>>>>assume s that you have used an autoidentifier key.
                >>>>>>>>
                >>>>>>>Howeve r I think that you have not declared any key in your
                >>>>>>>databa se 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:a4f b9$4598d1c6$539 0485a$2142@news .chello.pl...
                >>>>>>>>Robin S 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
                >>>>>>>>>agai n read for the data in your program? Does it
                >>>>>>>>>find it then?
                >>>>>>>>- after re-open the connection, there is no expected record
                >>>>>>>>>
                >>>>>>>>>Robi n S.
                >>>>>>>>>----------------------------
                >>>>>>>>>"b_r " <b_r@wp'_cut_it '.plwrote in message
                >>>>>>>>>news:1 e736$4597e2c1$5 390485a$12437@n ews.chello.pl.. .
                >>>>>>>>>>I'v e made some additional tests and the results are as
                >>>>>>>>>>follo ws:
                >>>>>>>>>>- 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
                >>>>>>>>>>(vi a dataadapter and data set) - Select * From Company
                >>>>>>>>>>- afer closing connection of course recordset disappears
                >>>>>>>>>>>
                >>>>>>>>>>It looks that this record is not finaly transited to
                >>>>>>>>>>datab ase...but why ???
                >>>>>>>>>>>
                >>>>>>>>>>>
                >>>>>>>>>>Branc o Medeiros napisa?(a):
                >>>>>>>>>>>b_ r wrote:
                >>>>>>>>>>>>Dat abase is correct - for sure...
                >>>>>>>>>>>>>
                >>>>>>>>>>>>Whe n I want to verify inserted row I got the following
                >>>>>>>>>>>>inf ormation:
                >>>>>>>>>>>>>
                >>>>>>>>>>>>A first chance exception of type
                >>>>>>>>>>>>'Sy stem.InvalidCas tException' occurred
                >>>>>>>>>>>>i n Microsoft.Visua lBasic.dll
                >>>>>>>>>>><sni p>
                >>>>>>>>>>>>
                >>>>>>>>>>>I guess Robin actually meant:
                >>>>>>>>>>>>
                >>>>>>>>>>><sni p>
                >>>>>>>>>>>>>Fo r Each dr As DataRow in dt.rows
                >>>>>>>>>>> Debug.print "Found CompanyName: " & dr("CompanyName ")
                >>>>>>>>>>>>>Ne xt dr
                >>>>>>>>>>><sni p>
                >>>>>>>>>>>>
                >>>>>>>>>>>HT H.
                >>>>>>>>>>>>
                >>>>>>>>>>>Rega rds,
                >>>>>>>>>>>>
                >>>>>>>>>>>Bran co.
                >>>>>>>>>>>>
                >
                >

                Comment

                • RobinS

                  #23
                  Re: ExecuteNonQuery - problem

                  Okay, I looked at this guy's code. It works with VS2005 and SQLServer.
                  So I think
                  it's a problem with his SQLServerExpres s 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:a076a$459b 95ef$5390485a$5 740@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@localhos twrote in message
                  >news:O%23reIpr LHHA.960@TK2MSF TNGP04.phx.gbl. ..
                  >>If AppDomain.Curre ntDomain.GetDat a("DataDirector y") 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:cb71e$45 9a9fda$5390485a $27234@news.che llo.pl...
                  >>>I used the following statement:
                  >>>Debug.Print( AppDomain.Curre ntDomain.GetDat a("DataDirector y")) - 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@localhos twrote in message
                  >>>>news:%23ISs z5mLHHA.4384@TK 2MSFTNGP03.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.Wr iteLine(AppDoma in.CurrentDomai n.GetData("Data Directory"))
                  >>>>>>
                  >>>>>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:3210c $459a5087$53904 85a$9299@news.c hello.pl...
                  >>>>>>Yes, of course there is primary key.
                  >>>>>>Initial y there was only one field "CompanyNam e" which was also
                  >>>>>>set as primary key - in order to simplify databse as much as
                  >>>>>>possibl e.
                  >>>>>>>
                  >>>>>>I made a lof of tests and now I have table:
                  >>>>>>Column Name DataType
                  >>>>>>ID int
                  >>>>>>CompanyNa me nvarchar(50)
                  >>>>>>>
                  >>>>>>where
                  >>>>>>Columns - ID (ASC)
                  >>>>>>Is Unique - Yes
                  >>>>>>Type - Primary Key
                  >>>>>>>
                  >>>>>>and the SQL is "INSERT INTO Company(ID, CompanyName) VALUES
                  >>>>>>(5,'four' )"
                  >>>>>>>
                  >>>>>>Everythin g looks ok but record is not inserted to database. As I
                  >>>>>>wrote before there is something strange because before closing
                  >>>>>>connectio n 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
                  >>>>>>>messag e 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.
                  >>>>>>>>>
                  >>>>>>>>Howev er I think that you have not declared any key in your
                  >>>>>>>>databas e 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 fb9$4598d1c6$53 90485a$2142@new s.chello.pl...
                  >>>>>>>>>Robi nS napisa³(a):
                  >>>>>>>>>>You'r e not using any kind of transactions, are you?
                  >>>>>>>>>- i'm not using any transaction
                  >>>>>>>>>>
                  >>>>>>>>>>So the problem is that you have an insert statement
                  >>>>>>>>>>tha t 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
                  >>>>>>>>>>dat a disappears, right?
                  >>>>>>>>>- yes, it is just as you wrote
                  >>>>>>>>>>
                  >>>>>>>>>>Wha t if you then re-open the connection and once
                  >>>>>>>>>>aga in read for the data in your program? Does it
                  >>>>>>>>>>fin d it then?
                  >>>>>>>>>- after re-open the connection, there is no expected record
                  >>>>>>>>>>
                  >>>>>>>>>>Rob in S.
                  >>>>>>>>>>----------------------------
                  >>>>>>>>>>"b_ r" <b_r@wp'_cut_it '.plwrote in message
                  >>>>>>>>>>news: 1e736$4597e2c1$ 5390485a$12437@ news.chello.pl. ..
                  >>>>>>>>>>>I' ve made some additional tests and the results are as
                  >>>>>>>>>>>foll ows:
                  >>>>>>>>>>>- the record is inserted but somwhere in the memory ??? -
                  >>>>>>>>>>>it is not visible in table
                  >>>>>>>>>>>- before closing connection to database I can see this
                  >>>>>>>>>>>reco rd (via dataadapter and data set) - Select * From
                  >>>>>>>>>>>Comp any
                  >>>>>>>>>>>- afer closing connection of course recordset disappears
                  >>>>>>>>>>>>
                  >>>>>>>>>>>It looks that this record is not finaly transited to
                  >>>>>>>>>>>data base...but why ???
                  >>>>>>>>>>>>
                  >>>>>>>>>>>>
                  >>>>>>>>>>>Bran co Medeiros napisa?(a):
                  >>>>>>>>>>>>b _r wrote:
                  >>>>>>>>>>>>>Da tabase is correct - for sure...
                  >>>>>>>>>>>>> >
                  >>>>>>>>>>>>>Wh en I want to verify inserted row I got the following
                  >>>>>>>>>>>>>in formation:
                  >>>>>>>>>>>>> >
                  >>>>>>>>>>>>> A first chance exception of type
                  >>>>>>>>>>>>>'S ystem.InvalidCa stException' occurred
                  >>>>>>>>>>>>> in Microsoft.Visua lBasic.dll
                  >>>>>>>>>>>><sn ip>
                  >>>>>>>>>>>>>
                  >>>>>>>>>>>>I guess Robin actually meant:
                  >>>>>>>>>>>>>
                  >>>>>>>>>>>><sn ip>
                  >>>>>>>>>>>>>>F or Each dr As DataRow in dt.rows
                  >>>>>>>>>>>> Debug.print "Found CompanyName: " & dr("CompanyName ")
                  >>>>>>>>>>>>>>N ext dr
                  >>>>>>>>>>>><sn ip>
                  >>>>>>>>>>>>>
                  >>>>>>>>>>>>HTH .
                  >>>>>>>>>>>>>
                  >>>>>>>>>>>>Reg ards,
                  >>>>>>>>>>>>>
                  >>>>>>>>>>>>Bra nco.
                  >>>>>>>>>>>>>
                  >>

                  Comment

                  Working...