hi
Actually i am trying to do a task given by my lead.First in a form i have grid view i have loaded my database content in that and i have a combobox there i have loaded my one column of my table in the combo box
.so i have two text fields and i wil type the data in the text field and i have a button below that when i press the button i should get updated in the database.please provide insert code also for the same.
the below is the code i am using..plese make changes and provide the code as soon as possible.thank you.
please provide me the full modified correct code data....:)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
FillData();
}
void FillData()
{
using (SqlConnection c = new SqlConnection("Data Source=.\\SQLEXPRESS;Integrated Security=True"))
//("Data Source=E:\\Vj_Test_1\\SRS\\WindowsApplication5\\WindowsApplication5\\DataSet3.xsd;Integrated Security=True"))
{
c.Open();
using (SqlDataAdapter a = new SqlDataAdapter(
"SELECT * FROM EmpDetails", c))
{
DataTable t = new DataTable();
a.Fill(t);
dataGridView1.DataSource = t;
string query = "select EmpID from EmpDetails";
SqlCommand cmd = new SqlCommand(query, c);
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
//MessageBox.Show(dr);
while (dr.Read())
{
comboBox1.Refresh();
query = dr[0].ToString();
//MessageBox.Show(query);
// comboBox1.DataSource = query;
comboBox1.Items.Add(query);
}
c.Close();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
// FillData();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string query1= "update EmpDetails set EmpName=" + textBox1.Text.Trim() + where EmpID=+comboBox1.Text+";
using (SqlConnection c2 = new SqlConnection("Data Source=.\\SQLEXPRESS;Integrated Security=True"))
{
SqlCommand command = new SqlCommand(query1, c2);
c2.Open();
SqlDataReader sqlReader = command.ExecuteReader();
while (sqlReader.Read())
{
// query1 = "update EmpDetails set EmpName=" + textBox1.Text.Trim() + "where comboBox1.TextUpdate=''";
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}