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)
        {

        }

Recommended Answers

All 4 Replies

Hi Sharan7081, welcome to DaniWeb.

DaniWeb users are more than happy to help you with any problems you might have, given that you can provide evidence that you've attempted to solve the problem youself and aren't just looking for someone to do the work for. (I think that might be why you have a down vote).

Having said that it sounds like you don't know where to start with this, so although I'm not going to give you the code I'll happily give you some ideas of what you need to do.

You can configure a DataGridView so that particular columns can be textBox columns, comboBox columns, checkBox columns as well as other types. Once you have chosen the type of column you want, using them is just like using a regular comboBox or textBox control (once you've accessed it through the DataGridViews columns property.

Here are a few links that might be of use to you:

DataGridViewComboBoxColumn class

DataGridViewComboBoxColumn DataSource

DataGrivViewTextBoxColumn class

Hope this helps and good luck.

commented: Very helpfull! +14

Actually i am a begineer i tried my level best.So i thought of taking some help from the users to solve the problem.Anyways i will try with the data you have provided.Thanks for ur support.I will solve the task and will contact you back if i face any issues.thank you.

your naming convention is a disaster.

SqlConnection c = new SqlConnection

Do not use variables like a, b, c...Rather give it a name, like Conn -> it helps. A lot.

ok.Thanks for your suggestion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.