TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ken H
NA
646
361k
How achieve batch update data
Jan 31 2012 10:27 PM
hi all,
I am trying to achieve batch update data, but failed to achieve, give correction, the code is as follows
thank in advance.
public partial class UpdateTranData : Form
{
public UpdateTranData()
{
InitializeComponent();
}
SqlDataAdapter adapter;
DataSet ds;
string connectionString = @"data source=StudentDB;initial catalog=MYDB;user=sa;password=PASSWORD;";
SqlConnection sqlCnn;
SqlCommand sqlCmd;
string sql = null;
private void UpdateTranData_Load(object sender, EventArgs e)
{
sql="SELECT *FROM TRAN_INFO";
sqlCnn = new SqlConnection(connectionString);
sqlCnn.Open();
adapter = new SqlDataAdapter(sql, sqlCnn);// specifing SQL statement and Database connection
ds = new DataSet();//creating instance of DataSet
adapter.Fill(ds); //filling DataSet
dataGridView1.DataSource = ds.Tables[0];//Binding DataGridView with DataSet
}
private void btnUpdate_Click(object sender, EventArgs e)
{
SqlCommandBuilder scb = new SqlCommandBuilder(adapter);
if (MessageBox.Show("Are you sure?","Warning",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)==DialogResult.Yes)
{
try
{
adapter.Update(ds.Tables[0]);
sqlCnn.Close();
MessageBox.Show("Data updated successful!");
}
catch (Exception)
{
MessageBox.Show("Data updated defeat!");
sqlCnn.Close();
}
}
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
txtID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
txtStart_Station.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
txtEnd_Station.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
txID.Enabled = false;
}
}
Reply
Answers (
1
)
Dynamic paging in datalist
How to split dynamic content to a page in fixed number of lines in vb.net