我有一个类Connect
来连接数据库。这是代码:
class Connect
{
SqlConnection con;
public Connect()
{
String connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + @"\Database1.mdf;Integrated Security=True;User Instance=True";
con = new SqlConnection(connectionString);
}
public DataTable executeSelect(String query)
{
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
adapter.Fill(dt);
con.Close();
return dt;
}
public void execute(String query)
{
con.Open();
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
}
}
我有DataGridView
这样:
代码如何将DataGridView
的所有数据插入Database
?