none
I am writting the code for saving the data to data base from GUI application. RRS feed

  • General discussion

  • Hi Friends

    I am beginner in ADO .Net and I want to store the data to data base from my GUI application for that I had written the code but it gives the error. Please help me.

    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 FirstADOPro
    {
        public partial class Form1 : Form
        {
            DataSet dt;
            DataRow dr;
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the 'empDataSet.Emp' table. You can move, or remove it, as needed.
                this.empTableAdapter.Fill(this.empDataSet.Emp);

            }

            private void button1_Click(object sender, EventArgs e)
            {
                //DataSet dt=new DataSet();
                dt = empDataSet.Tables["Emp"];
                 // I am making a "Emp" table in SQL where I did not make any primary key and declare only two
                  field Emp_Name and Emp_Age
                dr = dt.NewRow();
                dr[0] = textBox1.Text;
                dr[1] = textBox2.Text;
                dt.R
                empTableAdapter.Update(empDataSet);
                //textBox1.Text = System.Convert.ToString(dr[0]);
                textBox2.Text = System.Convert.ToString(dr[1]);
                textBox1.Text = false;
                textBox2.Text = false;
                this.empTableAdapter.Fill(this.empDataSet.Emp);
            }
        }
    }


    Please give the solution with explanation.

    Thank you

    Amit
    Saturday, December 27, 2008 12:29 PM

All replies

  • The hightlighted code seems not to be complete

    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 FirstADOPro  
    {  
        public partial class Form1 : Form  
        {  
            DataSet dt;  
            DataRow dr;  
            public Form1()  
            {  
                InitializeComponent();  
            }  
     
            private void Form1_Load(object sender, EventArgs e)  
            {  
                // TODO: This line of code loads data into the 'empDataSet.Emp' table. You can move, or remove it, as needed.  
                this.empTableAdapter.Fill(this.empDataSet.Emp);  
     
            }  
     
            private void button1_Click(object sender, EventArgs e)  
            {  
                //DataSet dt=new DataSet();  
                dt = empDataSet.Tables["Emp"];   
                 // I am making a "Emp" table in SQL where I did not make any primary key and declare only two  
                  field Emp_Name and Emp_Age  
                dr = dt.NewRow();  
                dr[0] = textBox1.Text;  
                dr[1] = textBox2.Text;  
                dt.R  
                empTableAdapter.Update(empDataSet);  
                //textBox1.Text = System.Convert.ToString(dr[0]);  
                textBox2.Text = System.Convert.ToString(dr[1]);  
                textBox1.Text = false;  
                textBox2.Text = false;  
                this.empTableAdapter.Fill(this.empDataSet.Emp);  
            }  
        }  
    }  
     

    I assume the code is dt.Rows.Add(dr);

    What is the error you get?
    Ewald - Please remember to mark the replies as answers if they help.
    Saturday, December 27, 2008 2:26 PM