PankaJ D

PankaJ D

  • NA
  • 154
  • 0

usretrive dataset

Mar 11 2010 12:57 AM

I have an following code in this I returned the dataset,but dont no how to use this dataset.

Plz help me...

====================================================

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;

using System.Data.SqlClient;

using MyFdll;

 

namespace UseDll1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        SqlConnection cn;

        DataSet ds = new DataSet();

        Class1 c1 = new Class1();

 

        string cnstring;

 

        private void btnSave_Click(object sender, EventArgs e)

        {

            cnstring =  "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "\\Database\\MasterFile.mdb;

           

 

         ds =(DataSet) c1.get_ds(cnstring, "insert into Stud values('" + txtname.Text + "'," + txtrno + ",'" + txtadd.Text + "')", " ");

            //Program is Running but ds is null

 

            MessageBox.Show("Record Sucessfully inserted", "Message");

 

        }

 

   }

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data;

 

using System.Data.SqlClient;

 

 

namespace MyFdll

{

    public class Class1

    {

        SqlConnection cn;

        DataSet dsm;

        SqlDataAdapter da1 ;

 

        public DataSet  get_ds(string cnstring,string oledbstr,string tb1)

        {

            cn = new SqlConnection(cnstring);

            dsm = new DataSet();

            try

            {

                cn.Open();

                da1 = new SqlDataAdapter(oledbstr,cn);

                if(tb1 != "")

                {

                    da1.Fill(dsm,tb1);

 

                }

                else

                {

                    da1.Fill(dsm);

                }

                return dsm;

            }

 

                catch (Exception ex)

            {

                    Console.WriteLine(ex.Message.ToString());

                }

            finally

            {

                cn.Close();

            }

            return dsm;

            }

 

        }

 

    }

 

 


Answers (2)