newly added record not showing up

S

Stephen

I posted this on the msdn forums but wasn't having any luck. I am
using Visual C#, .Net 2.0, and SQL Server Express (soon to be ported to
SQL Server).

I have a dataset, binding source, and table adapter used in a form. I
am binding the controls to the binding source. I use the SqlCommand
method to add a new record via a stored procedure instead of the table
adpater's update method. Once the stored procedure has added the
record, I return (output param) the primary key and pass that to a
query in my table adapter as a param to rebind the form. Basically
it's like this:

this.TableAdapter.FillBy(this.DataSet.tableName,
Convert.ToInt32(primaryKeyValue));

If I put a breakpoint in the code before this statement, the
primaryKeyValue valiable has the right value in it. I then switch to
the IDE and open the dataset from the designer, run the FillBy query
with the new param, and the record shows up. However, when I continue
to run the code from the breakpoint, the record doesn't populate the
form. Also, I have a datagrid on another form bound to the same data
table that I use as a record selection method (for selecting existing
records). A user can click a button to open this form, select the
record, and populate the form. Even if I use this method after adding
the record, the record doesn't show in the selection datagrid on this
other form. Its almost as if the data isn't getting refreshed or
something. I can stop the debugger, reopen the form and the data is
there. I have searched high and low through the dataset, data tables,
form controls, table adapters, and cannot find what might be causing
this. I have another project that uses identical processes to handle
records and it works. I have done side-by-side comparisons of the two
projects and everything looks like it should. I am getting tempted to
start from scratch with the dataset, bindingsource and table adapters
if I can't figure it out, but it would be alot of work that I would
like to avoid. Anyone have any ideas?


As a follow-up, I did try to delete the data table and recreate it and
all the queries but it still does the same thing.
 
S

Stephen

I got it working now. I ended up deleting the table adapter, binding
source, dataset, and the xsd file, then recreated them all. I never
did figure out what happened.
 
G

gregory.white

Stephen

There is a major flaw in the way c# express works with databases. You
will very likely run into problems again. I have been having the same
problem for weeks now and have had some luck connecting with people on
MSDN that have the same problem. The cause is that the original
database and the copy of the database in the solution explorer are not
kept in sync. The updates are saved to the copy ( in the project file )
and then the next time you compile , that database is overwritten by
the original database ( which doesnt have the updates). The next time
you load the datagrid, all updates are lost. If you right click the
database in the solution explorer and get its property, you will see
that there are three settings: "Copy if newer", Copy Always and Never
Copy. Try the "Copy if newer" setting and you will see what I mean. The
"Never Copy" just throws errors and can not be used. However, if you
open the database explorer , the timestamp will be changed and the
project database will be overwritten again and you are back to square
one. I have still not found a solution.

Greg
 
S

Stephen

I had read that in the forums, but I didn't think it applied to my
situation. Hmmm... that must account for the "database already
exists" errors I was getting too. It isn't a real big deal for me
because I will be porting it over to sql server as soon as I get my vs
2005 pro, but it was really a hassle because I spent many hours trying
to figure out why it was happening and wasted development time.

Thanks for the reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top