none
how to insert,update,delete rows from sql server tables RRS feed

  • Question

  • sir i m using below technique to connect the databade but now i m unable to add ,update any record please help me

    http://www.homeandlearn.co.uk/csharp/csharp_s12p1.html

    database name is mydb

    it contian 1 table namw INFO fields are

    id(primry key auto increament 1 ,) ,Name , Lname , job 

    i made a class name in Data

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace WindowsFormsApplication5
    {
        class DatabaseConnection
        {
            private string sql_string;
            private string strCon;
            System.Data.SqlClient.SqlDataAdapter da_1;


            public string Sql
            {
                set { sql_string = value; }
            }


            public string connection_string
            {
                set { strCon = value; }
            }


            public System.Data.DataSet GetConnection
            {

                get { return MyDataSet(); }

            }

    and my form data is 

                                          

    n

    amespace WindowsFormsApplication5
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            DatabaseConnection objCon1;
            string conSt1;
            DataSet ds1;
            DataRow dRow1;
            SqlConnection con;

            private void Form1_Load(object sender, EventArgs e)
            {
                objCon1 = new DatabaseConnection();
                conSt1 = Properties.Settings.Default.mydbConnectionString;
                objCon1.connection_string = conSt1;
                objCon1.Sql = Properties.Settings.Default.SQL;
                ds1 = objCon1.GetConnection;
                NavigateRecords();
            }
            private void NavigateRecords()
            {
                dRow1 = ds1.Tables[0].Rows[1];
                textBox1.Text = dRow1.ItemArray.GetValue(1).ToString();
                textBox2.Text = dRow1.ItemArray.GetValue(2).ToString();
                textBox3.Text = dRow1.ItemArray.GetValue(3).ToString();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                DataRow row = ds1.Tables[0].NewRow();
                row[1] = textBox1.Text;
                row[2] = textBox2.Text;
                row[3] = textBox3.Text;
                ds1.Tables[0].Rows.Add(row);
                objCon1.UpdateDatabase(ds1);


                MessageBox.Show("Database updated");



            }
        }

    }


    • Moved by CoolDadTx Friday, January 31, 2014 3:15 PM ADO.NET related
    Thursday, January 30, 2014 3:45 PM

Answers

All replies