using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using studentEditClass;
namespace studentEdit
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=database1;uid=sa;pwd=");
private SqlDataAdapter daStudent = new SqlDataAdapter();
private DataGridView dgStudent =new DataGridView ();
private DataSet dsStudent = new DataSet();
//private DataView medicine_dv = null;
//private BindingSource medicine_bind = new BindingSource();
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“database1DataSet.student”中。您可以根据需要移动或移除它。
this.studentTableAdapter.Fill(this.database1DataSet.student);
conn.Open();
/*SqlDataAdapter student_t = new SqlDataAdapter("select* from student",conn );
student_t.Fill(dsStudent, "student");
dgStudent.DataSource = dsStudent;
dgStudent.DataMember = "student";*/
}
private void button1_Click(object sender, EventArgs e)
{
string insertString = @"insert into student (sno,sname,sex) values ('"+textBox1 .Text+"' ,'"+textBox2 .Text+"' ,'"+textBox3 .Text+"' )";
SqlCommand cmd = new SqlCommand(insertString,conn );
cmd.ExecuteNonQuery();
SqlDataAdapter daaStudent = new SqlDataAdapter("select* from student", conn);
cmd.Connection =conn
daaStudent.SelectCommand = cmd;
daaStudent.Fill(dsStudent,"student");
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
}
}
我想用添加往datagrid里加记录,可加到表里,却不能在datagrid显示,错误在哪里??
[此贴子已经被作者于2007-11-3 10:08:03编辑过]