hi
i am working on a project, i want to pick up an excel file and display record in grid view, than
i have to save that file in sql server 2005 database name 'pension'
code to reterieve file and display in grid view controll is as follows:
private void button3_Click(object sender, EventArgs e)
{
DialogResult dr = this.openFileDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
string connectionString = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source={0};Extended Properties=""Excel
8.0;HDR=YES;IMEX=1;""", openFileDialog1.FileName);
string query = String.Format("select * from [{0}$]", "Sheet1");
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
dataGridView1.DataSource = dataSet.Tables[0];
}
}
this is working fine , now i want to save in database
private void button2_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlConnection cs = new SqlConnection("Data Source=admn\\SQLEXPRESS;Initial
Catalog=DB;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter();
da.InsertCommand = new SqlCommand("INSERT INTO Pension
VALUES(@ID,@Experience,@pension)", cs);
cs.Open();
da.InsertCommand.ExecuteNonQuery();
MessageBox.Show("Your value has been added");
cs.Close();
}
what to write code before cs.open, can any one help me out