I am unable to insert data into database, plz help me out.
This is my code

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;

namespace labsoft
{
    public partial class test_group : Form
    {
        Form opener;

        public test_group(Form parentForm)
        {
            InitializeComponent();
            opener = parentForm;
        }

        System.Data.SqlServerCe.SqlCeConnection con;
        System.Data.SqlServerCe.SqlCeDataAdapter da;
        DataSet ds1;


        int MaxRows = 0;
        int inc = 0;

        private void Form2_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'labworkDataSet1.test_main_group' table. You can move, or remove it, as needed.
            this.test_main_groupTableAdapter.Fill(this.labworkDataSet1.test_main_group);
            con = new System.Data.SqlServerCe.SqlCeConnection();
            con.ConnectionString = "Data Source=C:\\Users\\Dinesh\\Documents\\Visual Studio 2008\\Projects\\labsoft\\labsoft\\labwork.sdf";
            con.Open();
            ds1 = new DataSet();

            da = new System.Data.SqlServerCe.SqlCeDataAdapter();

            con.Close();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

           DataRow dRow =  ds1.Tables["test_main_group"].NewRow();
            dRow[1] = richTextBox1.Text;

            ds1.Tables["test_main_group"].Rows.Add(dRow);
            System.Data.SqlServerCe.SqlCeCommandBuilder cb;
            cb = new System.Data.SqlServerCe.SqlCeCommandBuilder(da);
            cb.DataAdapter.Update(ds1.Tables["test_main_group"]);

            MaxRows = MaxRows + 1;
            inc = MaxRows - 1;

            MessageBox.Show("added successfully");
        }

    }
}

Thank You in Advance for any answer

You generally need to leave some kind of error or at least more detail if you want to get help here.

This article has been dead for over six months. Start a new discussion instead.