Home > Net >  WPF problem for bosses to use c # binding mode=twoway but no update what might be the problem
WPF problem for bosses to use c # binding mode=twoway but no update what might be the problem

Time:09-19

 






This is part of the WPF controls

 
Public TeacherAddScore ()
{
InitializeComponent();


Ds=new studentDataSet ();
ScoreAdapter=new student. StudentDataSetTableAdapters. ScoreTableAdapter ();
StudentAdapter=new student. StudentDataSetTableAdapters. StudentTableAdapter ();
Dt=studentAdapter. GetData ();

}

StudentDataSet ds;
StudentDataSetTableAdapters. ScoreTableAdapter scoreAdapter;
StudentDataSetTableAdapters. StudentTableAdapter studentAdapter;
Public static DataTable dt;

Private void button1_Click (object sender, RoutedEventArgs e)
{
If (textBox1. Text. Length==0)
{
MessageBox. Show (" please fill out the subject ");
return;
}
ScoreAdapter. FillByClassName (ds) score, textBox1. Text);

DataRow Dr=null;
If (ds) Tables [r]. "score" Rows. Count==0)
{
for(int x=0; X{
Dr=ds. Tables [r]. "score" NewRow ();
Dr [" StudentNum "]=the Convert. ToInt32 (dt) Rows [x] [0]. ToString ());
Dr [" ClassName "]=textBox1. Text;
Dr [" score "]=0;
Ds. Tables [r]. "score" Rows. The Add (Dr);
}
}
For the IsEnabled=false;
TextBox1. IsReadOnly=true;
ListView1. ItemsSource=ds. Tables [r]. "score" DefaultView;

}

Private void button2_Click (object sender, RoutedEventArgs e)
{
If (ds) HasChanges ())
{
StudentAdapter. Update (ds);
}
}


CodePudding user response:


Connect themselves to make small database
This is a teacher's window
Is saved into database

CodePudding user response:

CodePudding user response:

SqlCommandBuilder sqlcmdbuilder=new SqlCommandBuilder less SqlCommandBuilder (studentAdapter)?

CodePudding user response:

The
reference 3 floor fuxiaoyang13 response:
SqlCommandBuilder sqlcmdbuilder=new SqlCommandBuilder less SqlCommandBuilder (studentAdapter)?

I tried shows the studentAdapter parameter form cannot convert?

CodePudding user response:

scoreAdapter. FillByClassName (ds) score, textBox1. Text); How about this one?

CodePudding user response:

Is it change the update to this if it is as useless

CodePudding user response:

reference 5 floor fuxiaoyang13 reply:
scoreAdapter. FillByClassName (ds) score, textBox1. Text); How about this one?

Is it change the update to this if it is as useless

CodePudding user response:

For I feel should not only the problem of update statement

I set the breakpoint before the update
In this sentence the ds the score data in the table is the default code 0
Not I input the value of the
So I suspect that the binding mode=twoway there may have a problem?
But in the end table is not even data 0
So can update problem

CodePudding user response:

If after the update to add the AcceptChanges ()

CodePudding user response:

references 9 f fuxiaoyang13 response:
if after the update to add the AcceptChanges ()

Emmm what to add

CodePudding user response:

StudentAdapter. Update (ds);
Ds. The AcceptChanges ();

CodePudding user response:

The
reference 11 floor fuxiaoyang13 response:
studentAdapter. Update (ds);
Ds. The AcceptChanges ();


As if it is no use
I found the ds didn't update the data before is the wrong I have a case
Now run the update ds data is right
But the update statement as if no work?

CodePudding user response:

Most of the time the update is not success is not the problem of Sql statements can breakpoints to see if the DataSet or the DataTable data change; I also recommend the use of EF framework using EFCore this stuff is easy to implement with linq is artifact here is a small demo:
Xaml code:
 



  •  Tags:  
  • C#
  • Related