Search update in textbox

Satyapriyanayak
Posted by Satyapriyanayak under C# category on | Points: 40 | Views : 821
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Search_Edit
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
string str;
DataSet ds;

public Form1()
{
InitializeComponent();
}

private void btn_edit_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from student where id='"+ textBox1.Text+"'";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
textBox2.Text=(reader["name"].ToString());
textBox3.Text = (reader["mark"].ToString());
}
reader.Close();
con.Close();
}

private void btn_update_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "update student set name='" + textBox2.Text + "',mark='" + textBox3.Text + "' where id='" + textBox1.Text + "'";
com = new OleDbCommand(str, con);
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Records successfully updated");
}
}
}

Comments or Responses

Login to post response