Answer to Question #200543 in C# for sana

Question #200543

Design a windows form application and Insert, update and delete data of patients visiting a private clinic using LINQ TO SQL queries.

Consider the following patient’s properties:

Name

Age

Bloodgroup

Symptoms

Prescribes medicines


1
Expert's answer
2021-05-31T05:40:24-0400
tizim yordamida ;  
 System.Data yordamida ;  
 System.Windows.Forms yordamida ;  
 System.Data.SqlClient yordamida ;  
  
nomlar maydoni  InsertUpdateDeleteDemo  
{  
    umumiy  qisman  sinf  frmMain: Form  
    {  
        SqlConnection con =  yangi  SqlConnection ( "Ma'lumotlar manbai = .; Dastlabki katalog = Namuna; Integrated Security = true;" );  
        SqlCommand cmd;  
        SqlDataAdapter moslashtirish;  
        // Yozuvni yangilash va o'chirish uchun ishlatiladigan ID o'zgaruvchisi  
        int  ID = 0;  
        public  frmMain ()  
        {  
            InitializeComponent ();  
            DisplayData ();  
        }  
        // Ma'lumotlarni joylashtiring  
        private void  btn_Insert_Click ( ob'ekt  yuboruvchisi, EventArgs e)   
        {  
            agar  (txt_Name.Text! =  ""  && txt_State.Text! =  "" )  
            {  
                cmd =  yangi  SqlCommand ( "tbl_Record (Name, State) qiymatlariga kiritish (@ name, @ state)" , con);  
                con.Open ();  
                cmd.Parameters.AddWithValue ( "@name" , txt_Name.Text);  
                cmd.Parameters.AddWithValue ( "@state" , txt_State.Text);  
                cmd.ExecuteNonQuery ();  
                con.Close ();  
                MessageBox.Show ( "Yozuv muvaffaqiyatli kiritildi" );  
                DisplayData ();  
                ClearData ();  
            }  
            boshqa  
            {  
                MessageBox.Show ( "Iltimos, batafsil ma'lumot bering!" );  
            }  
        }  
        // DataGridView-da ma'lumotlarni ko'rsatish  
        xususiy bo'shliq  DisplayData ()   
        {  
            con.Open ();  
            DataTable dt = yangi  DataTable ();  
adapt             = new  SqlDataAdapter ( "tbl_Record * dan tanlang" , con);  
            moslashtirish. to'ldiring (dt);  
            dataGridView1.DataSource = dt;  
            con.Close ();  
        }  
        // Ma'lumotlarni tozalash  
        xususiy bo'sh joy  ClearData ()   
        {  
            txt_Name.Text =  "" ;  
            txt_State.Text =  "" ;  
            ID = 0;  
        }  
        // dataGridView1 RowHeaderMouseClick Event  
        xususiy xoli  dataGridView1_RowHeaderMouseClick ( ob'ekt  jo'natuvchi, DataGridViewCellMouseEventArgs e)   
        {  
            ID = Convert.ToInt32 (dataGridView1.Rows [e.RowIndex] .Cells [0] .Value.ToString ());  
            txt_Name.Text = dataGridView1.Rows [e.RowIndex] .Cells [1] .Value.ToString ();  
            txt_State.Text = dataGridView1.Rows [e.RowIndex] .Cells [2] .Value.ToString ();  
        }  
        // Yozuvni yangilang  
        private void  btn_Update_Click ( ob'ekt  yuboruvchisi, EventArgs e)   
        {  
            agar  (txt_Name.Text! =  ""  && txt_State.Text! =  "" )  
            {  
                cmd =  yangi  SqlCommand ( "yangilash tbl_Record to'plami Name = @ name, State = @ state qaerda ID = @ id" , con);  
                con.Open ();  
                cmd.Parameters.AddWithValue ( "@id" , ID);  
                cmd.Parameters.AddWithValue ( "@name" , txt_Name.Text);  
                cmd.Parameters.AddWithValue ( "@state" , txt_State.Text);  
                cmd.ExecuteNonQuery ();  
                MessageBox.Show ( "Yozuv muvaffaqiyatli yangilandi" );  
                con.Close ();  
                DisplayData ();  
                ClearData ();  
            }  
            boshqa  
            {  
                MessageBox.Show ( "Yangilash uchun yozuvni tanlang" );  
            }  
        }  
        // Yozuvni o'chirish  
        private void  btn_Delete_Click ( ob'ekt  yuboruvchisi, EventArgs e)   
        {  
            agar (ID! = 0)  
            {  
                cmd =  yangi  SqlCommand ( "tbl_Record-ni o'chirib tashlang, bu erda ID = @ id" , con);  
                con.Open ();  
                cmd.Parameters.AddWithValue ( "@id" , ID);  
                cmd.ExecuteNonQuery ();  
                con.Close ();  
                MessageBox.Show ( "Yozuv muvaffaqiyatli o'chirildi!" );  
                DisplayData ();  
                ClearData ();  
            }  
            boshqa  
            {  
                MessageBox.Show ( "O'chirish uchun yozuvni tanlang" );  
            }  
        }  
    }  
}  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS