Hi Is there any way to refresh a DataSet after inserting few records in a table (containing foreignKey column) using adapters' InsertCommand and ExecuteNonQuery(). I tried adapter's Fill(dataSet) but it does not add the new records inserted to the dataset's table. I am doing something like: adapter->InsertCommand = gcnew SqlCommand(L"INSERT INTO Sample " + "(sampleID, type, dateReceived, dateExpiry, supplierID)"+ " VALUES (@sampID, @type, @dtRcvd, @dtExp, @suppID)", conn); int r = adapter->InsertCommand->ExecuteNonQuery(); adapter->Fill(dataset); Ofcourse all the parameter's are defined and the record is inserted to the dataSource table. Because of the foreignKey column I can not just add a newRow to DataSet and then use adapter's Update() method as it throws an exception. I am using VC++ (VisualStudio 2005 and SQL Server 2005) for the interface. Thanks for any information. Manjree
By default, Fill simply reexecutes the query and appends the new rows to an existing DataTable... did you look for the new rows at the end? -- ____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- [quoted text, click to view] "Manjree Garg" <garg@newsgroup.nospam> wrote in message news:B39F1381-1FB4-43FB-B49F-F2432D393236@microsoft.com... > Hi > > Is there any way to refresh a DataSet after inserting few records in a > table > (containing foreignKey column) using adapters' InsertCommand and > ExecuteNonQuery(). I tried adapter's Fill(dataSet) but it does not add the > new records inserted to the dataset's table. I am doing something like: > > adapter->InsertCommand = gcnew SqlCommand(L"INSERT INTO Sample " + > "(sampleID, type, dateReceived, dateExpiry, supplierID)"+ > " VALUES (@sampID, @type, @dtRcvd, @dtExp, @suppID)", conn); > > int r = adapter->InsertCommand->ExecuteNonQuery(); > adapter->Fill(dataset); > > Ofcourse all the parameter's are defined and the record is inserted to the > dataSource table. > > Because of the foreignKey column I can not just add a newRow to DataSet > and > then use adapter's Update() method as it throws an exception. > > I am using VC++ (VisualStudio 2005 and SQL Server 2005) for the interface. > > Thanks for any information. > > Manjree > > >
Thanks for your reply. I I am using dataset to list all the records in CListView. And after insertion when I list all the records in the table It does not list the newly inserted records. Though if I close the application and run it again all the records are listed via DataSet. Means that for the first time it Fills all the records but after insertion it does not refresh it. Manjree [quoted text, click to view] "William (Bill) Vaughn" wrote: > By default, Fill simply reexecutes the query and appends the new rows to an > existing DataTable... did you look for the new rows at the end? > > -- > ____________________________________ > William (Bill) Vaughn > Author, Mentor, Consultant > Microsoft MVP > INETA Speaker > www.betav.com/blog/billva > www.betav.com > Please reply only to the newsgroup so that others can benefit. > This posting is provided "AS IS" with no warranties, and confers no rights. > __________________________________ > Visit www.hitchhikerguides.net to get more information on my latest book: > Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) > and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) > ----------------------------------------------------------------------------------------------------------------------- > > "Manjree Garg" <garg@newsgroup.nospam> wrote in message > news:B39F1381-1FB4-43FB-B49F-F2432D393236@microsoft.com... > > Hi > > > > Is there any way to refresh a DataSet after inserting few records in a > > table > > (containing foreignKey column) using adapters' InsertCommand and > > ExecuteNonQuery(). I tried adapter's Fill(dataSet) but it does not add the > > new records inserted to the dataset's table. I am doing something like: > > > > adapter->InsertCommand = gcnew SqlCommand(L"INSERT INTO Sample " + > > "(sampleID, type, dateReceived, dateExpiry, supplierID)"+ > > " VALUES (@sampID, @type, @dtRcvd, @dtExp, @suppID)", conn); > > > > int r = adapter->InsertCommand->ExecuteNonQuery(); > > adapter->Fill(dataset); > > > > Ofcourse all the parameter's are defined and the record is inserted to the > > dataSource table. > > > > Because of the foreignKey column I can not just add a newRow to DataSet > > and > > then use adapter's Update() method as it throws an exception. > > > > I am using VC++ (VisualStudio 2005 and SQL Server 2005) for the interface. > > > > Thanks for any information. > > > > Manjree > > > > > > > >
How are you binding to the DataTable/DataView? -- ____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- [quoted text, click to view] "Manjree Garg" <garg@newsgroup.nospam> wrote in message news:E4EF2CA2-FF0C-4F18-96FC-D15B687F0D92@microsoft.com... > Thanks for your reply. I > > I am using dataset to list all the records in CListView. And after > insertion > when I list all the records in the table It does not list the newly > inserted > records. Though if I close the application and run it again all the > records > are listed via DataSet. Means that for the first time it Fills all the > records but after insertion it does not refresh it. > > Manjree > > "William (Bill) Vaughn" wrote: > >> By default, Fill simply reexecutes the query and appends the new rows to >> an >> existing DataTable... did you look for the new rows at the end? >> >> -- >> ____________________________________ >> William (Bill) Vaughn >> Author, Mentor, Consultant >> Microsoft MVP >> INETA Speaker >> www.betav.com/blog/billva >> www.betav.com >> Please reply only to the newsgroup so that others can benefit. >> This posting is provided "AS IS" with no warranties, and confers no >> rights. >> __________________________________ >> Visit www.hitchhikerguides.net to get more information on my latest book: >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) >> ----------------------------------------------------------------------------------------------------------------------- >> >> "Manjree Garg" <garg@newsgroup.nospam> wrote in message >> news:B39F1381-1FB4-43FB-B49F-F2432D393236@microsoft.com... >> > Hi >> > >> > Is there any way to refresh a DataSet after inserting few records in a >> > table >> > (containing foreignKey column) using adapters' InsertCommand and >> > ExecuteNonQuery(). I tried adapter's Fill(dataSet) but it does not add >> > the >> > new records inserted to the dataset's table. I am doing something like: >> > >> > adapter->InsertCommand = gcnew SqlCommand(L"INSERT INTO Sample " + >> > "(sampleID, type, dateReceived, dateExpiry, >> > supplierID)"+ >> > " VALUES (@sampID, @type, @dtRcvd, @dtExp, @suppID)", conn); >> > >> > int r = adapter->InsertCommand->ExecuteNonQuery(); >> > adapter->Fill(dataset); >> > >> > Ofcourse all the parameter's are defined and the record is inserted to >> > the >> > dataSource table. >> > >> > Because of the foreignKey column I can not just add a newRow to DataSet >> > and >> > then use adapter's Update() method as it throws an exception. >> > >> > I am using VC++ (VisualStudio 2005 and SQL Server 2005) for the >> > interface. >> > >> > Thanks for any information. >> > >> > Manjree >> > >> > >> > >> >> >>
Hi Bill I am just fetching the data from the DataTable's row and displaying in the list. The code is something like that: DataRowCollection^ rows = samplesTable->Rows; for (i = 0; i < rows->Count; i++) { row = rows->default[i]; supplierid = row->default[L"supplierID"]->ToString(); id = row->default[L"sampleID"]->ToString(); type = row->default[L"type"]->ToString(); int idx = lst.InsertItem(i, (CString)id); lst.SetItemText(idx, 1, (CString)supplierid); lst.SetItemText(idx, 2, (CString)type);; } After adding new records when I list the records It does not list the newly inserted records. Thanks. Manjree [quoted text, click to view] "William (Bill) Vaughn" wrote: > How are you binding to the DataTable/DataView? > > -- > ____________________________________ > William (Bill) Vaughn > Author, Mentor, Consultant > Microsoft MVP > INETA Speaker > www.betav.com/blog/billva > www.betav.com > Please reply only to the newsgroup so that others can benefit. > This posting is provided "AS IS" with no warranties, and confers no rights. > __________________________________ > Visit www.hitchhikerguides.net to get more information on my latest book: > Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) > and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) > ----------------------------------------------------------------------------------------------------------------------- > > "Manjree Garg" <garg@newsgroup.nospam> wrote in message > news:E4EF2CA2-FF0C-4F18-96FC-D15B687F0D92@microsoft.com... > > Thanks for your reply. I > > > > I am using dataset to list all the records in CListView. And after > > insertion > > when I list all the records in the table It does not list the newly > > inserted > > records. Though if I close the application and run it again all the > > records > > are listed via DataSet. Means that for the first time it Fills all the > > records but after insertion it does not refresh it. > > > > Manjree > > > > "William (Bill) Vaughn" wrote: > > > >> By default, Fill simply reexecutes the query and appends the new rows to > >> an > >> existing DataTable... did you look for the new rows at the end? > >> > >> -- > >> ____________________________________ > >> William (Bill) Vaughn > >> Author, Mentor, Consultant > >> Microsoft MVP > >> INETA Speaker > >> www.betav.com/blog/billva > >> www.betav.com > >> Please reply only to the newsgroup so that others can benefit. > >> This posting is provided "AS IS" with no warranties, and confers no > >> rights. > >> __________________________________ > >> Visit www.hitchhikerguides.net to get more information on my latest book: > >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) > >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) > >> ----------------------------------------------------------------------------------------------------------------------- > >> > >> "Manjree Garg" <garg@newsgroup.nospam> wrote in message > >> news:B39F1381-1FB4-43FB-B49F-F2432D393236@microsoft.com... > >> > Hi > >> > > >> > Is there any way to refresh a DataSet after inserting few records in a > >> > table > >> > (containing foreignKey column) using adapters' InsertCommand and > >> > ExecuteNonQuery(). I tried adapter's Fill(dataSet) but it does not add > >> > the > >> > new records inserted to the dataset's table. I am doing something like: > >> > > >> > adapter->InsertCommand = gcnew SqlCommand(L"INSERT INTO Sample " + > >> > "(sampleID, type, dateReceived, dateExpiry, > >> > supplierID)"+ > >> > " VALUES (@sampID, @type, @dtRcvd, @dtExp, @suppID)", conn); > >> > > >> > int r = adapter->InsertCommand->ExecuteNonQuery(); > >> > adapter->Fill(dataset); > >> > > >> > Ofcourse all the parameter's are defined and the record is inserted to > >> > the > >> > dataSource table. > >> > > >> > Because of the foreignKey column I can not just add a newRow to DataSet > >> > and > >> > then use adapter's Update() method as it throws an exception. > >> > > >> > I am using VC++ (VisualStudio 2005 and SQL Server 2005) for the > >> > interface. > >> > > >> > Thanks for any information. > >> > > >> > Manjree > >> > > >> > > >> > > >> > >> > >> > >
If you use one of the binding techniques, this refresh is done automatically. -- ____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- [quoted text, click to view] "Manjree Garg" <garg@newsgroup.nospam> wrote in message news:5ACF470B-C349-45B8-BBE3-13CBBD37878F@microsoft.com... > Hi Bill > > I am just fetching the data from the DataTable's row and displaying in the > list. The code is something like that: > > DataRowCollection^ rows = samplesTable->Rows; > for (i = 0; i < rows->Count; i++) > { > row = rows->default[i]; > supplierid = row->default[L"supplierID"]->ToString(); > id = row->default[L"sampleID"]->ToString(); > type = row->default[L"type"]->ToString(); > > int idx = lst.InsertItem(i, (CString)id); > lst.SetItemText(idx, 1, (CString)supplierid); > lst.SetItemText(idx, 2, (CString)type);; > } > > After adding new records when I list the records It does not list the > newly > inserted records. > > Thanks. > > Manjree > > "William (Bill) Vaughn" wrote: > >> How are you binding to the DataTable/DataView? >> >> -- >> ____________________________________ >> William (Bill) Vaughn >> Author, Mentor, Consultant >> Microsoft MVP >> INETA Speaker >> www.betav.com/blog/billva >> www.betav.com >> Please reply only to the newsgroup so that others can benefit. >> This posting is provided "AS IS" with no warranties, and confers no >> rights. >> __________________________________ >> Visit www.hitchhikerguides.net to get more information on my latest book: >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) >> ----------------------------------------------------------------------------------------------------------------------- >> >> "Manjree Garg" <garg@newsgroup.nospam> wrote in message >> news:E4EF2CA2-FF0C-4F18-96FC-D15B687F0D92@microsoft.com... >> > Thanks for your reply. I >> > >> > I am using dataset to list all the records in CListView. And after >> > insertion >> > when I list all the records in the table It does not list the newly >> > inserted >> > records. Though if I close the application and run it again all the >> > records >> > are listed via DataSet. Means that for the first time it Fills all the >> > records but after insertion it does not refresh it. >> > >> > Manjree >> > >> > "William (Bill) Vaughn" wrote: >> > >> >> By default, Fill simply reexecutes the query and appends the new rows >> >> to >> >> an >> >> existing DataTable... did you look for the new rows at the end? >> >> >> >> -- >> >> ____________________________________ >> >> William (Bill) Vaughn >> >> Author, Mentor, Consultant >> >> Microsoft MVP >> >> INETA Speaker >> >> www.betav.com/blog/billva >> >> www.betav.com >> >> Please reply only to the newsgroup so that others can benefit. >> >> This posting is provided "AS IS" with no warranties, and confers no >> >> rights. >> >> __________________________________ >> >> Visit www.hitchhikerguides.net to get more information on my latest >> >> book: >> >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) >> >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) >> >> ----------------------------------------------------------------------------------------------------------------------- >> >> >> >> "Manjree Garg" <garg@newsgroup.nospam> wrote in message >> >> news:B39F1381-1FB4-43FB-B49F-F2432D393236@microsoft.com... >> >> > Hi >> >> > >> >> > Is there any way to refresh a DataSet after inserting few records in >> >> > a >> >> > table >> >> > (containing foreignKey column) using adapters' InsertCommand and >> >> > ExecuteNonQuery(). I tried adapter's Fill(dataSet) but it does not >> >> > add >> >> > the >> >> > new records inserted to the dataset's table. I am doing something >> >> > like: >> >> > >> >> > adapter->InsertCommand = gcnew SqlCommand(L"INSERT INTO Sample " + >> >> > "(sampleID, type, dateReceived, dateExpiry, >> >> > supplierID)"+ >> >> > " VALUES (@sampID, @type, @dtRcvd, @dtExp, @suppID)", conn); >> >> > >> >> > int r = adapter->InsertCommand->ExecuteNonQuery(); >> >> > adapter->Fill(dataset); >> >> > >> >> > Ofcourse all the parameter's are defined and the record is inserted >> >> > to >> >> > the >> >> > dataSource table. >> >> > >> >> > Because of the foreignKey column I can not just add a newRow to >> >> > DataSet >> >> > and >> >> > then use adapter's Update() method as it throws an exception. >> >> > >> >> > I am using VC++ (VisualStudio 2005 and SQL Server 2005) for the >> >> > interface. >> >> > >> >> > Thanks for any information. >> >> > >> >> > Manjree >> >> > >> >> > >> >> > >> >> >> >> >> >> >> >> >>
Hi Bill Is it possible to bind data with Windows Forms in my current VC++ (MFC application) project? Manjree [quoted text, click to view] "William (Bill) Vaughn" wrote: > If you use one of the binding techniques, this refresh is done > automatically. > > -- > ____________________________________ > William (Bill) Vaughn > Author, Mentor, Consultant > Microsoft MVP > INETA Speaker > www.betav.com/blog/billva > www.betav.com > Please reply only to the newsgroup so that others can benefit. > This posting is provided "AS IS" with no warranties, and confers no rights. > __________________________________ > Visit www.hitchhikerguides.net to get more information on my latest book: > Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) > and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) > ----------------------------------------------------------------------------------------------------------------------- > > "Manjree Garg" <garg@newsgroup.nospam> wrote in message > news:5ACF470B-C349-45B8-BBE3-13CBBD37878F@microsoft.com... > > Hi Bill > > > > I am just fetching the data from the DataTable's row and displaying in the > > list. The code is something like that: > > > > DataRowCollection^ rows = samplesTable->Rows; > > for (i = 0; i < rows->Count; i++) > > { > > row = rows->default[i]; > > supplierid = row->default[L"supplierID"]->ToString(); > > id = row->default[L"sampleID"]->ToString(); > > type = row->default[L"type"]->ToString(); > > > > int idx = lst.InsertItem(i, (CString)id); > > lst.SetItemText(idx, 1, (CString)supplierid); > > lst.SetItemText(idx, 2, (CString)type);; > > } > > > > After adding new records when I list the records It does not list the > > newly > > inserted records. > > > > Thanks. > > > > Manjree > > > > "William (Bill) Vaughn" wrote: > > > >> How are you binding to the DataTable/DataView? > >> > >> -- > >> ____________________________________ > >> William (Bill) Vaughn > >> Author, Mentor, Consultant > >> Microsoft MVP > >> INETA Speaker > >> www.betav.com/blog/billva > >> www.betav.com > >> Please reply only to the newsgroup so that others can benefit. > >> This posting is provided "AS IS" with no warranties, and confers no > >> rights. > >> __________________________________ > >> Visit www.hitchhikerguides.net to get more information on my latest book: > >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) > >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) > >> ----------------------------------------------------------------------------------------------------------------------- > >> > >> "Manjree Garg" <garg@newsgroup.nospam> wrote in message > >> news:E4EF2CA2-FF0C-4F18-96FC-D15B687F0D92@microsoft.com... > >> > Thanks for your reply. I > >> > > >> > I am using dataset to list all the records in CListView. And after > >> > insertion > >> > when I list all the records in the table It does not list the newly > >> > inserted > >> > records. Though if I close the application and run it again all the > >> > records > >> > are listed via DataSet. Means that for the first time it Fills all the > >> > records but after insertion it does not refresh it. > >> > > >> > Manjree > >> > > >> > "William (Bill) Vaughn" wrote: > >> > > >> >> By default, Fill simply reexecutes the query and appends the new rows > >> >> to > >> >> an > >> >> existing DataTable... did you look for the new rows at the end? > >> >> > >> >> -- > >> >> ____________________________________ > >> >> William (Bill) Vaughn > >> >> Author, Mentor, Consultant > >> >> Microsoft MVP > >> >> INETA Speaker > >> >> www.betav.com/blog/billva > >> >> www.betav.com > >> >> Please reply only to the newsgroup so that others can benefit. > >> >> This posting is provided "AS IS" with no warranties, and confers no > >> >> rights. > >> >> __________________________________ > >> >> Visit www.hitchhikerguides.net to get more information on my latest > >> >> book: > >> >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) > >> >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) > >> >> ----------------------------------------------------------------------------------------------------------------------- > >> >> > >> >> "Manjree Garg" <garg@newsgroup.nospam> wrote in message > >> >> news:B39F1381-1FB4-43FB-B49F-F2432D393236@microsoft.com... > >> >> > Hi > >> >> > > >> >> > Is there any way to refresh a DataSet after inserting few records in > >> >> > a > >> >> > table > >> >> > (containing foreignKey column) using adapters' InsertCommand and > >> >> > ExecuteNonQuery(). I tried adapter's Fill(dataSet) but it does not > >> >> > add > >> >> > the > >> >> > new records inserted to the dataset's table. I am doing something > >> >> > like: > >> >> > > >> >> > adapter->InsertCommand = gcnew SqlCommand(L"INSERT INTO Sample " + > >> >> > "(sampleID, type, dateReceived, dateExpiry, > >> >> > supplierID)"+ > >> >> > " VALUES (@sampID, @type, @dtRcvd, @dtExp, @suppID)", conn); > >> >> > > >> >> > int r = adapter->InsertCommand->ExecuteNonQuery(); > >> >> > adapter->Fill(dataset); > >> >> > > >> >> > Ofcourse all the parameter's are defined and the record is inserted > >> >> > to > >> >> > the > >> >> > dataSource table. > >> >> > > >> >> > Because of the foreignKey column I can not just add a newRow to > >> >> > DataSet > >> >> > and > >> >> > then use adapter's Update() method as it throws an exception. > >> >> > > >> >> > I am using VC++ (VisualStudio 2005 and SQL Server 2005) for the > >> >> > interface. > >> >> > > >> >> > Thanks for any information. > >> >> > > >> >> > Manjree > >> >> > > >> >> > > >> >> > > >> >> > >> >> > >> >> > >> > >> > >> > >
While I don't understand why you're using VC++, the code to do this can be created by Visual Studio 2005 or you should be able to do it yourself. -- ____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- [quoted text, click to view] "Manjree Garg" <garg@newsgroup.nospam> wrote in message news:40B5CD72-A6C3-41CE-9E1A-CE4F0B19CA7B@microsoft.com... > Hi Bill > > Is it possible to bind data with Windows Forms in my current VC++ (MFC > application) project? > > Manjree > > "William (Bill) Vaughn" wrote: > >> If you use one of the binding techniques, this refresh is done >> automatically. >> >> -- >> ____________________________________ >> William (Bill) Vaughn >> Author, Mentor, Consultant >> Microsoft MVP >> INETA Speaker >> www.betav.com/blog/billva >> www.betav.com >> Please reply only to the newsgroup so that others can benefit. >> This posting is provided "AS IS" with no warranties, and confers no >> rights. >> __________________________________ >> Visit www.hitchhikerguides.net to get more information on my latest book: >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) >> ----------------------------------------------------------------------------------------------------------------------- >> >> "Manjree Garg" <garg@newsgroup.nospam> wrote in message >> news:5ACF470B-C349-45B8-BBE3-13CBBD37878F@microsoft.com... >> > Hi Bill >> > >> > I am just fetching the data from the DataTable's row and displaying in >> > the >> > list. The code is something like that: >> > >> > DataRowCollection^ rows = samplesTable->Rows; >> > for (i = 0; i < rows->Count; i++) >> > { >> > row = rows->default[i]; >> > supplierid = row->default[L"supplierID"]->ToString(); >> > id = row->default[L"sampleID"]->ToString(); >> > type = row->default[L"type"]->ToString(); >> > >> > int idx = lst.InsertItem(i, (CString)id); >> > lst.SetItemText(idx, 1, (CString)supplierid); >> > lst.SetItemText(idx, 2, (CString)type);; >> > } >> > >> > After adding new records when I list the records It does not list the >> > newly >> > inserted records. >> > >> > Thanks. >> > >> > Manjree >> > >> > "William (Bill) Vaughn" wrote: >> > >> >> How are you binding to the DataTable/DataView? >> >> >> >> -- >> >> ____________________________________ >> >> William (Bill) Vaughn >> >> Author, Mentor, Consultant >> >> Microsoft MVP >> >> INETA Speaker >> >> www.betav.com/blog/billva >> >> www.betav.com >> >> Please reply only to the newsgroup so that others can benefit. >> >> This posting is provided "AS IS" with no warranties, and confers no >> >> rights. >> >> __________________________________ >> >> Visit www.hitchhikerguides.net to get more information on my latest >> >> book: >> >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) >> >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) >> >> ----------------------------------------------------------------------------------------------------------------------- >> >> >> >> "Manjree Garg" <garg@newsgroup.nospam> wrote in message >> >> news:E4EF2CA2-FF0C-4F18-96FC-D15B687F0D92@microsoft.com... >> >> > Thanks for your reply. I >> >> > >> >> > I am using dataset to list all the records in CListView. And after >> >> > insertion >> >> > when I list all the records in the table It does not list the newly >> >> > inserted >> >> > records. Though if I close the application and run it again all the >> >> > records >> >> > are listed via DataSet. Means that for the first time it Fills all >> >> > the >> >> > records but after insertion it does not refresh it. >> >> > >> >> > Manjree >> >> > >> >> > "William (Bill) Vaughn" wrote: >> >> > >> >> >> By default, Fill simply reexecutes the query and appends the new >> >> >> rows >> >> >> to >> >> >> an >> >> >> existing DataTable... did you look for the new rows at the end? >> >> >> >> >> >> -- >> >> >> ____________________________________ >> >> >> William (Bill) Vaughn >> >> >> Author, Mentor, Consultant >> >> >> Microsoft MVP >> >> >> INETA Speaker >> >> >> www.betav.com/blog/billva >> >> >> www.betav.com >> >> >> Please reply only to the newsgroup so that others can benefit. >> >> >> This posting is provided "AS IS" with no warranties, and confers no >> >> >> rights. >> >> >> __________________________________ >> >> >> Visit www.hitchhikerguides.net to get more information on my latest >> >> >> book: >> >> >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) >> >> >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) >> >> >> ----------------------------------------------------------------------------------------------------------------------- >> >> >> >> >> >> "Manjree Garg" <garg@newsgroup.nospam> wrote in message >> >> >> news:B39F1381-1FB4-43FB-B49F-F2432D393236@microsoft.com... >> >> >> > Hi >> >> >> > >> >> >> > Is there any way to refresh a DataSet after inserting few records >> >> >> > in >> >> >> > a >> >> >> > table >> >> >> > (containing foreignKey column) using adapters' InsertCommand and >> >> >> > ExecuteNonQuery(). I tried adapter's Fill(dataSet) but it does >> >> >> > not >> >> >> > add >> >> >> > the >> >> >> > new records inserted to the dataset's table. I am doing something >> >> >> > like: >> >> >> > >> >> >> > adapter->InsertCommand = gcnew SqlCommand(L"INSERT INTO Sample " >> >> >> > + >> >> >> > "(sampleID, type, dateReceived, dateExpiry, >> >> >> > supplierID)"+ >> >> >> > " VALUES (@sampID, @type, @dtRcvd, @dtExp, @suppID)", conn); >> >> >> > >> >> >> > int r = adapter->InsertCommand->ExecuteNonQuery(); >> >> >> > adapter->Fill(dataset); >> >> >> > >> >> >> > Ofcourse all the parameter's are defined and the record is >> >> >> > inserted >> >> >> > to >> >> >> > the >> >> >> > dataSource table. >> >> >> > >> >> >> > Because of the foreignKey column I can not just add a newRow to >> >> >> > DataSet >> >> >> > and >> >> >> > then use adapter's Update() method as it throws an exception. >> >> >> > >> >> >> > I am using VC++ (VisualStudio 2005 and SQL Server 2005) for the >> >> >> > interface. >> >> >> > >> >> >> > Thanks for any information. >> >> >> >
Hello Manjree Thanks for Bill's help. It seems Bill have resolved your issue. Do you still have anything unclear? Please feel free to update here if there is anything we can help with. We're glad to assist you. Have a great day, Sincerely, Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello WenYuan Well! I am completely confused. First I must explain my problem properly. I've a VC++ Project (VS2005). I have to add database support to the existing project. I am using ADO.Net for that. I am trying to add a new record to a SampleTable that has a foreignKey column. So I am using Adapter's InserCommand for that (as Update() throws an exception because of the foreignKey). The problem is that it adds record to to DataSource but when I refresh the DataSet using Adapter->Fill(dataSet) It does not refresh it as I can not list the newly added records in the list (CListView class). As Bill suggested databinding, I can not find any way of adding a complete Windows Forms to my exixsing VC++ project (though there are ways to include windows form control). Thanks for any information. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree > Thanks for Bill's help. > > It seems Bill have resolved your issue. > Do you still have anything unclear? > Please feel free to update here if there is anything we can help with. > We're glad to assist you. > > Have a great day, > Sincerely, > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hi WenYuan An Another problem with ADO.net using in VC++. To delete a record in Parent Table, How can I set up the ForeignKeyConstraint's DeleteRule. I am trying something like following with parent column pCol and child column cCol: sampFKC = gcnew ForeignKeyConstraint(pCol,cCol); sampFKC->DeleteRule = Rule->SetNull; which is giving error error C2275: 'System::Data::Rule' : illegal use of this type as an expression How do I declare 'Rule'. Thanks Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree > Thanks for Bill's help. > > It seems Bill have resolved your issue. > Do you still have anything unclear? > Please feel free to update here if there is anything we can help with. > We're glad to assist you. > > Have a great day, > Sincerely, > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Dear Manjree I think it should be something like sampFKC->DeleteRule=System::Data::Rule::SetNull; Hope this helps. Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Dear Manjree, According to your description, you meet an issue that the inserted data rows are not retrieved by dataadapter. However, if you close the application and open it again, all new records are listed via DataSet. If I misunderstand anything, please correct me thanks. For such issue, please check the following two sections. 1) Please make sure new records have been inserted into underlying database. You may open the underlying database and check each table and rows. 2) Please change the code snippet you pasted in the initial post. What if you clear the dataset and fill it again? Will all rows be retrieved by DataAdatper? int r = adapter->InsertCommand->ExecuteNonQuery(); dataset->Clear(); adapter->Fill(dataset); If this is the case, the issue may relate to adapter or dataset. Please kindly test the above method and let me know the result. We are glad to assist you. Have a great day, Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks WenYuan. It worked. I have got another problem. I am deleting records in the database using stored procedure in sql2005. The procedure is: CREATE PROCEDURE dbo.DeleteSupp (@suppID VarChar) AS /* SET NOCOUNT ON */ DELETE FROM Supplier WHERE supplierID = @suppID DELETE FROM SamplePrep WHERE sampleID = ANY (SELECT sampleID FROM Sample WHERE supplierID = @suppID) DELETE FROM Sample WHERE supplierID = @suppID RETURN The problem is that it does not work when I supply a value for @suppID (say 'nnn')but if in place of @suppID I give any value say: DELETE FROM Supplier WHERE supplierID = 'nnn' then it deletes the record. Thanks for your support. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Dear Manjree > > I think it should be something like > sampFKC->DeleteRule=System::Data::Rule::SetNull; > > Hope this helps. > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Dear WenYuan You understood my problem very well. I checked; the records are being inserted into the database but as you say are not being retrieved by the adapter to refresh the dataset. I tried exactly the same code you suggested but it clears the data set but doesnot fill it again. Thanks. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Dear Manjree, > > According to your description, you meet an issue that the inserted data > rows are not retrieved by dataadapter. However, if you close the > application and open it again, all new records are listed via DataSet. If I > misunderstand anything, please correct me thanks. > > For such issue, please check the following two sections. > 1) Please make sure new records have been inserted into underlying database. > You may open the underlying database and check each table and rows. > > 2) Please change the code snippet you pasted in the initial post. > What if you clear the dataset and fill it again? Will all rows be > retrieved by DataAdatper? > > int r = adapter->InsertCommand->ExecuteNonQuery(); > dataset->Clear(); > adapter->Fill(dataset); > > If this is the case, the issue may relate to adapter or dataset. > > Please kindly test the above method and let me know the result. We are glad > to assist you. > Have a great day, > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Dear Manjree, Sorry for the delay, due to weekend. [quoted text, click to view] >> int r = adapter->InsertCommand->ExecuteNonQuery(); >>dataset->Clear(); >> adapter->Fill(dataset); >I tried exactly the same code you suggested but it clears the data set but
does not fill it again. Do you mean the adapter doesn't fill dataset again after we cleared dataset? I suspect the select command of current adapter has been modified before we use it to fill cleared dataset. Select command is the component which Dbdataadapter used it for filling dataset. When we call Dbdataadapter'fill method, the implement of Dbdataadapter will call its Select command's execute method to retrieve the data rows from the underlying database. Thus, if the Dbdataadpter could not get rows from underlying database, there is something wrong with select command. Please check the commandText property of this command before filling data into dataset int r = adapter->InsertCommand->ExecuteNonQuery(); dataset->Clear(); System::Console::WriteLine(adapter->SelectCommand->CommandText); // please let me know the output string. adapter->Fill(dataset); Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Dear Manjree, Did you receive any error message when you executed SP from ado.net? For such issue, I would like to suggest you use SQL profile to trace server. 1) Open SQL 2005 Server Management Studio. 2) Connect your Database Server and click "connect" button. 3) Click Tools|SQL Server Profile in the menu. * Note: SQL server 2005 express edition doesn't have SQL Server Profile. If you are developing with this edition, please let me know. 4) Connect your Database server and click "connect" button again in the SQL Server Profile. 5) Create a new trace and select "Run" button with default configuration. 6) Reproduce the issue. 7) After repro the issue, please stop the select trace in SQL Server Profile. 8) Save the trace file as SQL Server Profile trace file (*.trc) (File|Saveas|TraceFile) Please packet the trace file and send it to me (v-wywang@microsoft.com). By the way, please let me know the exact database name and stored procedure name. I will review on it. Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Dear WenYuan When I use single table in adapter to fill in the dataset it works. But I am using two tables (will be using more in future) of the database at the moment in adapter. In that case it does not fill in the data set again. Though it clears it. I checked the select command of the current adapter it is same. I am doing something like: String^ allSuppliers = L"SELECT * FROM Supplier"; String^ allSamples = L"SELECT * FROM Sample"; String^ select = String::Format(L"{0};{1}",allSuppliers,allSamples); commandBuilder = gcnew SqlCommandBuilder(adapter); conn->Open(); dataset = gcnew DataSet(); adapter = gcnew SqlDataAdapter(select,conn); adapter->Fill(dataset); DataTableCollection^ tables = dataset->Tables; tables->default[0]->TableName = L"AllSuppliers"; tables->default[1]->TableName = L"AllSamples"; suppliersTable = tables->default[L"AllSuppliers"]; samplesTable = tables->default[L"AllSamples"]; This is the initialisation code that connects to the database and fills in the dataset in the begining and works fine. Then I add a sample record in another function AddSample() where I am doing something like: dataset->Clear(); adapter->Fill(dataset); DataTableCollection^ tables = dataset->Tables; tables->default[0]->TableName = L"AllSuppliers"; tables->default[1]->TableName = L"AllSamples"; nRows = tables->default[L"AllSamples"]->Rows->Count; str.Format("Records = %d ", nRows); AfxMessageBox(str); Here, it clears the dataset but does not fills it again as the no. of records it gives is 0. I checked the commandTextProperty and the output string it gives is: SELECT* FROM Supplier;SELECT * From Sample Which is same as earlier. Thanks for all Information. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Dear Manjree, > Sorry for the delay, due to weekend. > > >> int r = adapter->InsertCommand->ExecuteNonQuery(); > >>dataset->Clear(); > >> adapter->Fill(dataset); > >I tried exactly the same code you suggested but it clears the data set but > does not fill it again. > > Do you mean the adapter doesn't fill dataset again after we cleared dataset? > I suspect the select command of current adapter has been modified before we > use it to fill cleared dataset. > > Select command is the component which Dbdataadapter used it for filling > dataset. > When we call Dbdataadapter'fill method, the implement of Dbdataadapter will > call its Select command's execute method to retrieve the data rows from the > underlying database. Thus, if the Dbdataadpter could not get rows from > underlying database, there is something wrong with select command. > Please check the commandText property of this command before filling data > into dataset > > int r = adapter->InsertCommand->ExecuteNonQuery(); > dataset->Clear(); > System::Console::WriteLine(adapter->SelectCommand->CommandText); > // please let me know the output string. > adapter->Fill(dataset); > > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Manjree, The DBDataAdapter creates new DataTable named as Table[i] in dataset, and then fill data into it. If there have been already some tables in current dataset, it will append new table behind them. According to the code snippet, you have filled dataset before. Thus there are two tables (AllSuppliers and AllSamples) in the current dataset. Then, after a while, you fill the dataset again. As I mentioned above, DBDataAdapter inserted two new DataTable behind AllSupplier table and AllSamples table. DataSet->clear() method deletes all the rows in current dataset, therefore, you notice there is no rows in DataSet->tables->default[0] table. Actually, new tables have been inserted as DataSet->tables->default[2] and DataSet->tables->default[3]. Please check these tables, is there any row in it? For your case, what we need is dataset->Reset() method. Reset() method clears all the rows in tables, deletes all the tables in dataset also. Then, new tables will be inserted as fist and second table in current dataset again. Please try the following method, and kindly let me know if this is what you need. dataset->Reset(); adapter->Fill(dataset); DataTableCollection^ tables = dataset->Tables; tables->default[0]->TableName = L"AllSuppliers"; tables->default[1]->TableName = L"AllSamples"; nRows = tables->default[L"AllSamples"]->Rows->Count; str.Format("Records = %d ", nRows); AfxMessageBox(str); Hope this helps. Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Wen Thanks for the reply. It did work. So, Every time I refresh the dataset I need to rename the tables. I m setting up the first column of each table as the primary key. Do I need to reset the primary keys as well every time I refresh the dataset ? Regards Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree, > > The DBDataAdapter creates new DataTable named as Table[i] in dataset, and > then fill data into it. If there have been already some tables in current > dataset, it will append new table behind them. > > According to the code snippet, you have filled dataset before. Thus there > are two tables (AllSuppliers and AllSamples) in the current dataset. Then, > after a while, you fill the dataset again. As I mentioned above, > DBDataAdapter inserted two new DataTable behind AllSupplier table and > AllSamples table. DataSet->clear() method deletes all the rows in current > dataset, therefore, you notice there is no rows in > DataSet->tables->default[0] table. > > Actually, new tables have been inserted as DataSet->tables->default[2] and > DataSet->tables->default[3]. Please check these tables, is there any row in > it? > > For your case, what we need is dataset->Reset() method. > Reset() method clears all the rows in tables, deletes all the tables in > dataset also. > Then, new tables will be inserted as fist and second table in current > dataset again. > Please try the following method, and kindly let me know if this is what you > need. > > dataset->Reset(); > adapter->Fill(dataset); > DataTableCollection^ tables = dataset->Tables; > tables->default[0]->TableName = L"AllSuppliers"; > tables->default[1]->TableName = L"AllSamples"; > nRows = tables->default[L"AllSamples"]->Rows->Count; > str.Format("Records = %d ", nRows); > AfxMessageBox(str); > > Hope this helps. > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Manjree, Yes, this is nessary. Because DataSet.Reset method not only clears all the rows in each table, but also deletes each table in current dataset. It is necessary for us to set up the schema again for your new dataset (primary keys and relationships). By the way, for your informatioin, there is anyother approach by using TableMappings. TableMappings could specify which table DBDataAdatper will fill in. We could define which table in dataset we want to fill data in. Therefor, we doesn't delete all datatables, but fill the new datas in related table. Look at the following code snippet. String^ allSuppliers = L"SELECT * FROM Supplier"; String^ allSamples = L"SELECT * FROM Sample"; String^ select = String::Format(L"{0};{1}",allSuppliers,allSamples); commandBuilder = gcnew SqlCommandBuilder(adapter); dataset = gcnew DataSet(); adapter = gcnew SqlDataAdapter(select,conn); adapter->Fill(dataset); DataTableCollection^ tables = dataset->Tables; tables->default[0]->TableName = L"AllSuppliers"; tables->default[1]->TableName = L"AllSamples"; *adapter->TableMappings->Add("Table"," AllSuppliers"); //this line of code means the first table(supplier) need to fill in the table named ALLsuppliers. *adapter->TableMappings->Add("Table1"," AllSamples"); //this line of code means the second table(Samples) need to fill the table named ALLSamples. *dataset->Clear(); //This time, we need clear the dataset rather than reset all tables. This means we still reserve the primary key in current tables. Thus we need not set up schema again. adapter->Fill(dataset); DataTableCollection^ tables = dataset->Tables; nRows = tables->default[L"AllSamples"]->Rows->Count; str.Format("Records = %d ", nRows); AfxMessageBox(str); Hope this helps. Let me know if you have anything unclear. We are glad to assist. Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Thankyou so much Wen. It's great. Table mapping saved a lot of work. I really appreciate your help. I'll be posting you in future whenever I'll have some doubts. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree, > > Yes, this is nessary. Because DataSet.Reset method not only clears all the > rows in each table, but also deletes each table in current dataset. It is > necessary for us to set up the schema again for your new dataset (primary > keys and relationships). > > By the way, for your informatioin, there is anyother approach by using > TableMappings. > TableMappings could specify which table DBDataAdatper will fill in. We > could define which table in dataset we want to fill data in. Therefor, we > doesn't delete all datatables, but fill the new datas in related table. > Look at the following code snippet. > > String^ allSuppliers = L"SELECT * FROM Supplier"; > String^ allSamples = L"SELECT * FROM Sample"; > String^ select = String::Format(L"{0};{1}",allSuppliers,allSamples); > commandBuilder = gcnew SqlCommandBuilder(adapter); > dataset = gcnew DataSet(); > adapter = gcnew SqlDataAdapter(select,conn); > adapter->Fill(dataset); > DataTableCollection^ tables = dataset->Tables; > tables->default[0]->TableName = L"AllSuppliers"; > tables->default[1]->TableName = L"AllSamples"; > > *adapter->TableMappings->Add("Table"," AllSuppliers"); > //this line of code means the first table(supplier) need to fill in the > table named ALLsuppliers. > *adapter->TableMappings->Add("Table1"," AllSamples"); > //this line of code means the second table(Samples) need to fill the table > named ALLSamples. > *dataset->Clear(); > //This time, we need clear the dataset rather than reset all tables. This > means we still reserve the primary key in current tables. Thus we need not > set up schema again. > > adapter->Fill(dataset); > DataTableCollection^ tables = dataset->Tables; > nRows = tables->default[L"AllSamples"]->Rows->Count; > str.Format("Records = %d ", nRows); > AfxMessageBox(str); > > Hope this helps. Let me know if you have anything unclear. We are glad to > assist. > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
You are welcome, Manjree. I'm standing by. Feel free to update here again.:) We are glad to assist you. Have a great weekend. Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Wen Is there any way of linking text file to a table's field. I have a table Experiment that contains all the information about Experiment (e.g. Raman spectra) like date, type, sample etc. I need to find some way to access that experiment's data (which is lots of text files) from VC++ user interface. Perhaps I did not make it very clear. Thanks. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > You are welcome, Manjree. > I'm standing by. Feel free to update here again.:) > We are glad to assist you. > > Have a great weekend. > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Manjree, I'm not sure I have understood your issue very clear. It seems you need to store a text file into Table, isn't it? If this is the case, we usually have two options. 1) Save the file path in the field of table. If you need to read the file, we can locate the file by file path which is stored in table. 2) Save the text file as Binary in the field of table. If necessary, we can read binary stream from the table and print it for display. Hope this helps. Please feel free to correct me if I misunderstood anything here. We are glad to assist. Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks Wen. You got my problem very clear. The text file contains 2 columns (xVal and yVal) that I'ld like to store into 2 fields of the 'ExpData' table as binary. To save the text files into ExpData table using VC++ interface, is there any way of browsing the directory and getting the file name/path rather then typing the full pathname for each file in an edit control of the dialog box? Means, How to add the functionality of browsing the filename in the directories? Thanks again. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree, > > I'm not sure I have understood your issue very clear. > It seems you need to store a text file into Table, isn't it? > > If this is the case, we usually have two options. > 1) Save the file path in the field of table. If you need to read the file, > we can locate the file by file path which is stored in table. > 2) Save the text file as Binary in the field of table. If necessary, we can > read binary stream from the table and print it for display. > > Hope this helps. Please feel free to correct me if I misunderstood anything > here. We are glad to assist. > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Wen I found it out. I have to use CFileDialog fopendialog(). Now the problem is that when I click on 'Browse' button of 'AddData' dialog box it does not open the file open dialog box. Though I have added function on BnClicked event of 'Browse' button in which I am using CFileDialog fopendialog(). The problem is that it does not go to the BnClicked function. I need to know is there any way of executing a BnClicked function of a button of a dialog box? Thanks Manjree [quoted text, click to view] "Manjree Garg" wrote: > Thanks Wen. You got my problem very clear. The text file contains 2 columns > (xVal and yVal) that I'ld like to store into 2 fields of the 'ExpData' table > as binary. > > To save the text files into ExpData table using VC++ interface, is there any > way of browsing the directory and getting the file name/path rather then > typing the full pathname for each file in an edit control of the dialog box? > Means, How to add the functionality of browsing the filename in the > directories? > > Thanks again. > > Manjree > > > "WenYuan Wang [MSFT]" wrote: > > > Hello Manjree, > > > > I'm not sure I have understood your issue very clear. > > It seems you need to store a text file into Table, isn't it? > > > > If this is the case, we usually have two options. > > 1) Save the file path in the field of table. If you need to read the file, > > we can locate the file by file path which is stored in table. > > 2) Save the text file as Binary in the field of table. If necessary, we can > > read binary stream from the table and print it for display. > > > > Hope this helps. Please feel free to correct me if I misunderstood anything > > here. We are glad to assist. > > Sincerely, > > Wen Yuan > > Microsoft Online Community Support > > ================================================== > > This posting is provided "AS IS" with no warranties, and confers no rights. > >
Hello Manjree, Thanks for your reply. It seems your objective is to open a File Dialog (CFileDialog) when clicking "Browse" button in "AddData" Dialog. I'm not sure what the "AddData" Dialog is. Is it CFileDialog? Actually, I cannot found "Browse" button in CFileDialog. There are "Open" button and "Cancel" button in CFileDialog. Am I missing something here? Have a great day, Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Wen I sorted it out using CFileDialog fopendialog(). If there is any other way please let me know. Another thing is reading two columns of a text files into two seperate fields of a table (xVal and yVal). When we use Byte Stream it takes whole text file as a stream. Thanks. Manjree [quoted text, click to view] "Manjree Garg" wrote: > Hello Wen > > I found it out. I have to use CFileDialog fopendialog(). > Now the problem is that when I click on 'Browse' button of 'AddData' dialog > box it does not open the file open dialog box. Though I have added function > on BnClicked event of 'Browse' button in which I am using CFileDialog > fopendialog(). The problem is that it does not go to the BnClicked function. > > I need to know is there any way of executing a BnClicked function of a > button of a dialog box? > > Thanks > > Manjree > > "Manjree Garg" wrote: > > > Thanks Wen. You got my problem very clear. The text file contains 2 columns > > (xVal and yVal) that I'ld like to store into 2 fields of the 'ExpData' table > > as binary. > > > > To save the text files into ExpData table using VC++ interface, is there any > > way of browsing the directory and getting the file name/path rather then > > typing the full pathname for each file in an edit control of the dialog box? > > Means, How to add the functionality of browsing the filename in the > > directories? > > > > Thanks again. > > > > Manjree > > > > > > "WenYuan Wang [MSFT]" wrote: > > > > > Hello Manjree, > > > > > > I'm not sure I have understood your issue very clear. > > > It seems you need to store a text file into Table, isn't it? > > > > > > If this is the case, we usually have two options. > > > 1) Save the file path in the field of table. If you need to read the file, > > > we can locate the file by file path which is stored in table. > > > 2) Save the text file as Binary in the field of table. If necessary, we can > > > read binary stream from the table and print it for display. > > > > > > Hope this helps. Please feel free to correct me if I misunderstood anything > > > here. We are glad to assist. > > > Sincerely, > > > Wen Yuan > > > Microsoft Online Community Support > > > ================================================== > > > This posting is provided "AS IS" with no warranties, and confers no rights. > > >
Hello Wen This issue is resolved now. I am able to read a text file and store as binary data. But the next issue is to store two columns (xVal and yVal) of the text file into two different fields (xValue and yValue) of the 'ExpData' table. I guess there is StreamReader class that can be used to read a line of the stream but again that line contains two double values that need to be stored (appended) in xValue and yValue fields of the table. Thanks for your time. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree, > Thanks for your reply. > It seems your objective is to open a File Dialog (CFileDialog) when > clicking "Browse" button in "AddData" Dialog. > I'm not sure what the "AddData" Dialog is. Is it CFileDialog? Actually, I > cannot found "Browse" button in CFileDialog. There are "Open" button and > "Cancel" button in CFileDialog. > Am I missing something here? > > Have a great day, > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Wen Thanks for the reply. I guess the best thing will be to store the file as binary in one field and when reading it back for display or any other processing then split it into xVal and yVal. Another thing is that the 'Console' doesn't work in my VC++ application, e.g. the following code does not display anything on console: Console::WriteLine( "<none>" ); any idea why? Thanks again. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree, > Thanks for your reply. > > Yes, as you seen, StreamReader class provides a feature to read string from > Txt file. > > http://msdn2.microsoft.com/en-us/library/system.io.streamreader.readline.asp > x > [StreamReader.ReadLine Method] > > In my opinion, we could read one line from txt file and split it into > xValue and yValue. Covent each Vaule(xValue and yValue) to binary by > Encoding.GetBytes method and store them into "ExpData" table. Does this > work in your scenario? > http://msdn2.microsoft.com/en-us/library/ds4kkd55.aspx > [Encoding.GetBytes Method (String)] > > Hope this helps, > Best regards, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Manjree, Thanks for your reply. Yes, as you seen, StreamReader class provides a feature to read string from Txt file. http://msdn2.microsoft.com/en-us/library/system.io.streamreader.readline.asp x [StreamReader.ReadLine Method] In my opinion, we could read one line from txt file and split it into xValue and yValue. Covent each Vaule(xValue and yValue) to binary by Encoding.GetBytes method and store them into "ExpData" table. Does this work in your scenario? http://msdn2.microsoft.com/en-us/library/ds4kkd55.aspx [Encoding.GetBytes Method (String)] Hope this helps, Best regards, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Wen Thanks for the reply. My VC++ application is an MFC application. I guess Console::Write works in 'CLR Console' application. Is there some way of declaring the size of stored procedures parameters of type VarChar (MAX) or VarBinary(MAX) in VC++ ADO.NET code, like I need to declare an array of 'Byte' type that will store the binary data from the 'ExpData' table's 'data' column which has been declared of datatype VarBinary(MAX) . I am doing some thing like following as the max size limit of this type is (2^31-1). array<Byte>^ data = gcnew array<Byte>(2^31-1); Is there any way of knowing the exact size instead of giving the maximum limits. The same problem is with VarChar(MAX). How do we declare procedure's parameter's size in ADO.NET. Thanks for your time. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree > Thanks for your reply. > > Console::WriteLine Writes the specified data to the standard output stream. > Console::Out could get the standard output stream. > > If you face an issue that Console::WriteLine doesn't display anything on > console, I would like to suggest you check current standard output stream > (Console::Out). > > http://msdn2.microsoft.com/en-us/library/system.console.out.aspx > [Console.Out Property] > > Would you please let me know what does Console::out return? (is it null?) > > I'm looking forward to your reply. > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Wen In continuation to my earlier reply I am trying to read a binary value from a DataRow object and then output that data to a file. I am doing the following: array<Object^>^ search = gcnew array<Object^>(1); search[0] = dataID; DataRow^ row = expDataTable->Rows->Find(search); array<Byte>^ data = gcnew array<Byte>(2^31-1); data = (Byte[]) (row->default[L"data"]); to read data from the VarBinary(MAX) field 'data' of 'expDataTable'. its giving following compilation error in the last line. error C2440: 'type cast' : cannot convert from 'System::Object ^' to 'unsigned char []' 1> There are no conversions to array types, although there are conversions to references or pointers to arrays 1>.\DatabaseConn.cpp(106) : error C2440: '=' : cannot convert from 'unsigned char []' to 'cli::array<Type> ^' any suggestion will be appreciated. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree > Thanks for your reply. > > Console::WriteLine Writes the specified data to the standard output stream. > Console::Out could get the standard output stream. > > If you face an issue that Console::WriteLine doesn't display anything on > console, I would like to suggest you check current standard output stream > (Console::Out). > > http://msdn2.microsoft.com/en-us/library/system.console.out.aspx > [Console.Out Property] > > Would you please let me know what does Console::out return? (is it null?) > > I'm looking forward to your reply. > Sincerely, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Manjree Thanks for your reply. Console::WriteLine Writes the specified data to the standard output stream. Console::Out could get the standard output stream. If you face an issue that Console::WriteLine doesn't display anything on console, I would like to suggest you check current standard output stream (Console::Out). http://msdn2.microsoft.com/en-us/library/system.console.out.aspx [Console.Out Property] Would you please let me know what does Console::out return? (is it null?) I'm looking forward to your reply. Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Manjree, I have repro this issue on my side. In C# world, we use following line to retrieve Byte array from DataTable. Byte[] b = (Byte[])ds.Tables[0].Rows[0][1]; However, it seems there is something different in C++.net world. I need to perform more research on this issue and reply here as soon as possible. If you have any more concerns on it, please feel free to post here. Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Manjree, Thanks for your wait. I searched on internet and found out a KB article about how to retrieve BLOB by ADO.net in C++.net. http://support.microsoft.com/kb/317044/EN-US/ [HOW TO: Read and Write a File to and from a BLOB Column by Using ADO.NET and Visual C++ .NET] Would you please check if this method works for you? If you have any issue on this, please feel free to update here. I'm glad to assist you. Best regards, Wen Yuan Microsoft Online Community Support ================================================= This posting is provided "AS IS" with no warranties, and confers no rights.
Dear Wen I tried the method but its giving compilation error in the following GetBytes() method when used first time to determine the size of the data array. int size = (Convert::ToInt32(dr->GetBytes(dataCol, 0, 0, 0, Int32::MaxValue))); array<Byte>^ data = gcnew array<Byte>(size); dr->GetBytes(dataCol, 0, data, 0, data->Length); Where dr is the DataReader. The error is: error C2664: '__int64 System::Data::Common::DbDataReader::GetBytes(int,__int64,cli::array<Type,dimension> ^,int,int)' : cannot convert parameter 3 from 'int' to 'cli::array<Type,dimension> ^' Is there any way of using DataSet instead of DataReader? Thanks for your time. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree, > Thanks for your wait. > > I searched on internet and found out a KB article about how to retrieve > BLOB by ADO.net in C++.net. > > http://support.microsoft.com/kb/317044/EN-US/ > [HOW TO: Read and Write a File to and from a BLOB Column by Using ADO.NET > and Visual C++ .NET] > > Would you please check if this method works for you? > If you have any issue on this, please feel free to update here. I'm glad to > assist you. > > Best regards, > Wen Yuan > Microsoft Online Community Support > ================================================= > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Manjree, Thanks for your reply. It seems you'd like to retrieve byte array from Dataset, rather than DataReader. However, I searched on MSDN website. There is No article related to this so far. For DataSet, I have tried the following method on my side. array<Byte>^ b=(array<Byte>^)ds->Tables[0]->Rows[0]->default[2]; Would you please try this method and let me know if this is what you need. I'm glad to assist you. System::Data::SqlClient::SqlConnection^ cn = gcnew System::Data::SqlClient::SqlConnection("Data Source=.;Initial Catalog=ImageDB;Integrated Security=True"); System::Data::SqlClient::SqlCommand^ cmd = gcnew System::Data::SqlClient::SqlCommand("SELECT * from Nodes", cn); System::Data::SqlClient::SqlDataAdapter^ sda=gcnew System::Data::SqlClient::SqlDataAdapter(cmd); System::Data::DataSet^ ds=gcnew System::Data::DataSet(); sda->Fill(ds); array<Byte>^ b=(array<Byte>^)ds->Tables[0]->Rows[0]->default[2]; Hope this helps, Best regards, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Wen I tried the method. My code is: DataRow^ row = expDataTable->Rows->Find(search); array<Byte>^ data = gcnew array<Byte>(2^31-1); data = (array<Byte>^)(row->default[L"data"]); int size = data->GetUpperBound(0); But it is throwing following exception in line 3: "Object reference is not set to an instance of an object." I guess we are using an array declaration as casting operator which is not working. If I use a DataReader that was giving the compilation error as I mentioned in my earlier reply. Is there any way out of it? Thanks for any information provided. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree, > Thanks for your reply. > > It seems you'd like to retrieve byte array from Dataset, rather than > DataReader. However, I searched on MSDN website. There is No article > related to this so far. > > For DataSet, I have tried the following method on my side. > array<Byte>^ b=(array<Byte>^)ds->Tables[0]->Rows[0]->default[2]; > > Would you please try this method and let me know if this is what you need. > I'm glad to assist you. > System::Data::SqlClient::SqlConnection^ cn = gcnew > System::Data::SqlClient::SqlConnection("Data Source=.;Initial > Catalog=ImageDB;Integrated Security=True"); > System::Data::SqlClient::SqlCommand^ cmd = gcnew > System::Data::SqlClient::SqlCommand("SELECT * from Nodes", cn); > System::Data::SqlClient::SqlDataAdapter^ sda=gcnew > System::Data::SqlClient::SqlDataAdapter(cmd); > System::Data::DataSet^ ds=gcnew System::Data::DataSet(); > sda->Fill(ds); > > array<Byte>^ b=(array<Byte>^)ds->Tables[0]->Rows[0]->default[2]; > > Hope this helps, > Best regards, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hello Manjree, This is System.NullReferenceException. I'd like to suggest you check if there is object returned by expDataTable->Rows->Find(search) method. Please change your code as below, and check if it will thow System.NullReferenceException in Line 2. DataRow^ row = expDataTable->Rows->Find(search); System::Object^ o=row->default[L"data"]; array<Byte>^ data = (array<Byte>^)o; Using an Array declaration as casting operator should be the correct method. Under my test, It works fine. Please try the above method and let me know if NullReferenceException thown in Line 2. System::Object^ o=row->default[L"data"]; Hope this helps, Best regards, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks Wen. You are right. The problem was in Find(). It did work. Thanks a lot for your time. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > Hello Manjree, > > This is System.NullReferenceException. > I'd like to suggest you check if there is object returned by > expDataTable->Rows->Find(search) method. > > Please change your code as below, and check if it will thow > System.NullReferenceException in Line 2. > > DataRow^ row = expDataTable->Rows->Find(search); > System::Object^ o=row->default[L"data"]; > array<Byte>^ data = (array<Byte>^)o; > > Using an Array declaration as casting operator should be the correct method. > Under my test, It works fine. > > Please try the above method and let me know if NullReferenceException thown > in Line 2. > System::Object^ o=row->default[L"data"]; > > Hope this helps, > Best regards, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
You are welcome, Manjree. Have a great day, Best regards, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Wen I am trying to include a CCheckListBox into my VC++ user interface. In the on line help it says to declare a class derived from the CCheckListBox and then use its Create function. I am doing the same as shown in the example: class CMyCheckListBox : public CCheckListBox { DECLARE_DYNAMIC(CMyCheckListBox) // Constructors public: CMyCheckListBox(); BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID); }; and then declaring a variable of this class like: CMyCheckListBox chListBox; chListBox.Create(.....); but as there is no definition of the Create function in my code it is giving the error: error LNK2001: unresolved external symbol "public: virtual int __thiscall CMyCheckListBox::Create(unsigned long,struct tagRECT const &,class CWnd *,unsigned int)" (?Create@CMyCheckListBox@@UAEHKABUtagRECT@@PAVCWnd@@I@Z) What's the right way of using it? I couldn't find any example of it. If you could let me know that will be great. Thanks. Manjree [quoted text, click to view] "WenYuan Wang [MSFT]" wrote: > > You are welcome, Manjree. > > Have a great day, > Best regards, > Wen Yuan > Microsoft Online Community Support > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Hi Manjree, Did you have an implementation of CMyCheckListBox::Create in your .cpp file? I just saw the declaration of Create function in the header file, however I did not see its implementation. What is the result if you add the implementation in your MyCheckListBox.cpp file: BOOL CMyCheckListBox::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID) { //To do something for your customization ...... return TRUE; } Also, I strongly recommend that you declare your Create method with virtual modifier since you would like to override the member function of the base class: virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID); Hope this helps. Please feel free to let us know if you have any other questions or concerns. Best regards, Charles Wang Microsoft Online Community Support ===================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from this issue. ====================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ======================================================
Hello Manjree, It seems this is a MFC issue (which is different from ADO.net), but not very complex. I have discussed with another support engineer (Charles Wang) who owned MFC issue in Newsgroup (microsoft.public.vc.mfc). He will follow up here by the end of today. Please wait a moment. thanks. However, I'm afraid this thread is too long (included 54 posts). It's really difficult to read and check the issue status. Would you please post a new thread in group next time? Therefore, our community member and us could read it easy and provide more information.:) The completed MSDN managed newsgroup list could be found here: http://msdn2.microsoft.com/en-us/subscriptions/aa974230.aspx In MSDN managed newsgroup, our engineers will monitor every issue thread posted by MSDN subscribers. For MFC issue, you may post it in microsoft.public.vc.mfc. This is also managed newsgroup, we will follow up on time. In additon, more people and MVPs could help you in the related filed. Have a great day. Please let me know if you have any more concern on this. We are glad to assist you. Best regards, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Don't see what you're looking for? Try a search.
|