SqlCommand in ado.net – Part 4

40
26



Text version of the video

Slides

All ADO .NET Text Articles

All ADO .NET Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

In this video we will learn about
1. The Purpose of the SqlCommand object
2. Creating an instance of the SqlCommand class
3. When and how to use ExecuteReader(), ExecuteScalar() and ExecuteNonQuery() methods of the SqlCommand object.

Nguồn: https://chaoticpharmacology.com/

Xem thêm bài viết khác: https://chaoticpharmacology.com/cong-nghe/

40 COMMENTS

  1. hello sir! why we have done totalrows.toString() when already the method executNonQuey is returning a integer value which we are storing in an integer variable?

  2. Sir can you put video of one small project then we come to know how to use all these regarding C# && asp.net..

  3. in Response.Write() we can use "n" instead of "<br/>", right? And why is it that "<br/>" works anyway? Because I don't think that would work in C++'s cout. Is <br> defined for C#?

  4. Hi,
    Following code is not working.

    using System;

    using System.Data.SqlClient;

    using System.Configuration;

    namespace TestData

    {

    public class Program

    {

    public static void Main()

    {

    string CS= ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;

    SqlConnection con = new SqlConnection(CS);

    SqlCommand cm = new SqlCommand("");

    cm.CommandText = "select *from Students_Table";

    cm.Connection = con;

    con.Open();

    SqlDataReader dr =cm.ExecuteReader();

    while(dr.Read())

    {

    Console.WriteLine(dr["Id"]+"t"+dr["Name"]+"t"+dr["Course"]);

    }

    cm.CommandText = "delete from Students_Table where Id=1";

    int count = cm.ExecuteNonQuery();

    Console.WriteLine("No of rows deleted are" + count);

    cm.CommandText = "select count(Id) from Students_Table";

    count = (int)cm.ExecuteScalar();

    Console.WriteLine("Total students are" + count);

    con.Close();

    }

    }

    }

    If I run all execute methods at a time, on opening a connection only once. It is throwing an error as below.

    There is already an open DataReader associated with this Command which must be closed first.'

  5. I have no words man, thank you so much for these awesome and simple explanations. I have a test in 9 days and haven't managed to study properly because of my job. I sit here 2 or 3 hours a day listening to you and I get a full week of class in a day

  6. I'm facing a problem with web application I don"t get the data in the GridView at the browser but in the Windows Forms Application i can .

  7. I have to say thank you for creating this playlist. These videos are just such a great resource. Having said that, I have been struggling with a problem for the last few days and I just can't find the help to solve it all the way. I am not senior in C# so forgive me if I am missing something simple here. Here is the question – I am trying to write a script in SSIS which converts a System.Object into a list of strings so I can then select the Max value from all the strings, how can I do that exactly because using the data adapter just doesn't work for me. I don't care if i convert to a list of strings or a data column, or an array – I just need to select the Max value stored in the System.Object. Please help! And thanks again for these videos.

  8. Hi Venkat
    i am a beginner to ADO.Net
    This video is very help for learning things quicky..thanks alottt
    i tired delete command with ExecuteReader instead of ExecuteNonQuery.. and it deleted the row from table
    so what is the main difference between ExecuteReader and ExecuteNonQuery
    Please Help to understand..

  9. Why do we have to convert the total rows to ToString in Response.Write()? Can't we simply write as TotalRows and not TotalRows.ToString()?

  10. Oh guy! You saved my marks. Today I had an exam and it went wonderful. All because of you. Thank you so much! 😊

  11. I get an error with the line GridView1.DataBind();The intelesence does not show the DataBind() method at all.Thank you

LEAVE A REPLY

Please enter your comment!
Please enter your name here