views:

473

answers:

4

WPF and C#: Problem: 1. How to Refresh Radgridview when i Insert,update and Delete Record in database anrecord. 2.when i am Insert or Update Record than in radgridview that row is selected.

i am useing sql server 2005.

i am use to set data source of radgridview like " radgridview1.ItemsSource = ds; " ==> ds is dataset.

i am beginner so if possible than tel me by code it is easy to understand.......

can u help me as early as possible ....

i give some code which i am useing for update RadGridview

con.ConnectionString = @"Data Source=(local);Initial Catalog=DigiDms;Integrated Security=True";

        cmd1.Connection = con;
        con.Open();
        cmd1.CommandType = CommandType.StoredProcedure;
        cmd1.CommandText = "Pro_Insurance_Master_Select";
        da1.SelectCommand = cmd1;
        da1.Fill(ds1);
        con.Close();

        //dataGrid.clear();
        //dsGrid.Reset();
        //dsGrid = dataGrid.GetData("Pro_Insurance_Master_Select"); //set datasource of gridview

        gridShowData.ItemsSource = null;
        gridShowData.ItemsSource = ds1;

doing this ,

when i am delete or update record than folloning error generated... Error: >> "Object reference not set to an object"
when i am doing the "gridShowData.ItemsSource = null;"

and when i am doing insert operation than this error is not generated and RadGridview also updated.....

so pls help me as early as possible.... i am beginer ........

my email address is [email protected]

A: 

Dear patelriki13, one way is that you can call the function in which you are binding the datasource of gridview

the other way is that call the datasource again using stored procedure or linq and bind it again with that gridview.

calling function and binding datasource would be done in those button click which are used for insert,delete and update.

i think you just create a function and bind gridview in it and call it in page_load, after that call that function in insert,delete,update function after performing the desire task.

Emaad Ali
i am useing WPF Window application and i am do u say but not done. same porblem
Patel Rikin
you call the function again in which you are binding gridview?in insert,delete and update function?
Emaad Ali
A: 

i am useing WPF Window application and i am do u say but not done. same porblem

Patel Rikin
A: 

pls help me ....pls...

Patel Rikin
A: 

hi frds i got ans

i am useing selected row event in this we get the information about selected row ...

so for that i use Gridview1.selectedItem but instead of this we use Gridview1.CurrentItem

and

before Reload the data we make null the selected item of Gridview

so Gridview1.SelectedItem = null;

so enjoy sharing idea to other........

Patel Rikin