解决方案 »

  1.   

    代码没有。 你是怎么绑定到datagrid上的??使用binding机制了么,如果使用的话,修改与删除也就简单了。操作后台绑定的集合就行了。
      

  2.   

     MySQLConnection conn = null;
                conn = new MySQLConnection(new MySQLConnectionString("localhost", "studentsystem", "root", "1234").AsString);
                conn.Open();
                string sql = "select count(*) from stuinfos where UserName ='" + textBox1.Text + "'";
                MySQLCommand mda = new MySQLCommand(sql, conn);
                string s;
                if (radioButton1.IsChecked == false)
                {
                    s = (string)radioButton2.Content;
                }
                else s = (string)radioButton1.Content;
                object obj = mda.ExecuteScalar();
                if (obj == null || obj == DBNull.Value)
                {
                    listBox1.Items.Add(textBox1.Text + " 数据已经存在");
                    MessageBox.Show("添加失败!");
                }
                else if(textBox2.Text==textBox3.Text)
                {
                    MySQLCommand commn = new MySQLCommand("insert into stuinfos(UserName,Password,Name,Sex,Age,Tel,Email,Address) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox4.Text + "','" + s + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "') ", conn);
                    listBox1.Items.Add(textBox1.Text + " 成功添加");
                    if (commn.ExecuteNonQuery() > 0) MessageBox.Show("添加成功!");
                    else MessageBox.Show("添加失败!");
                    Login l1 = new Login();
                    string sql1 = "select * from stuinfos ";
                    MySQLDataAdapter mda1 = new MySQLDataAdapter(sql1, conn);
                    DataSet ds = new DataSet();
                    mda1.Fill(ds, "table1");
                    l1.Show();
                    l1.datagrid.ItemsSource = ds.Tables[0].DefaultView;
                    commn.Dispose();
                    conn.Close();
                }else
                    MessageBox.Show("两次密码不一致!");
    这个我进行添加的代码,可以加载到数据库,之后跳转回DataGrid也可以。
      

  3.   

    http://msdn.microsoft.com/zh-cn/magazine/dd252944.aspx
      

  4.   

    我是想弄的简单点,就是每一条数据后面可以有两个按钮或者是链接进行删除和修改,可是我现在不知道怎么添加这个两个按钮或链接 <DataGridTemplateColumn Header="Operating Items" MinWidth="230" Width="*">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Background="White" BorderBrush="White"  BorderThickness="1" Margin="-1">
                                                <Button Content="Edit" x:Name="btnEdit" Width="50" Height="28" Margin="5,0,0,0" Style="{StaticResource myBtnStyle1}"></Button>
                                        </Border>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
      

  5.   

    我是想弄的简单点,就是每一条数据后面可以有两个按钮或者是链接进行删除和修改,可是我现在不知道怎么添加这个两个按钮或链接 <DataGridTemplateColumn Header="Operating Items" MinWidth="230" Width="*">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Background="White" BorderBrush="White"  BorderThickness="1" Margin="-1">
                                                <Button Content="Edit" x:Name="btnEdit" Width="50" Height="28" Margin="5,0,0,0" Style="{StaticResource myBtnStyle1}"></Button>
                                        </Border>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>

    我用的是WPF啊,控件中没有这个属性啊</DataGridTemplateColumn.CellTemplate>
      

  6.   

    添加到 <DataGrid.Columns> </DataGrid.Columns>里。懂??????
      

  7.   

    可是按着这个添加按钮,他报错了,"在“System.Windows.Markup.StaticResourceHolder”上提供值时引发了异常。"
      

  8.   

     Style="{StaticResource myBtnStyle1}"   这句 去掉。