19 October 2011

Call SQL Server Stored Procedures in ASP.NET by Using Visual C# .NET


Call SQL Server Stored Procedures in ASP.NET by Using Visual C# .NET


private void btnGetAuthors_Click(object sender, System.EventArgs e)
 {
  //Create a connection to the SQL Server; modify the connection string for your environment.
  //SqlConnection MyConnection = new SqlConnection("server=(local);database=pubs;Trusted_Connection=yes");
  SqlConnection MyConnection = new SqlConnection("server=(local);database=pubs;UID=myUser;PWD=myPassword;");

  //Create a DataAdapter, and then provide the name of the stored procedure.
  SqlDataAdapter MyDataAdapter = new SqlDataAdapter("GetAuthorsByLastName", MyConnection);

  //Set the command type as StoredProcedure.
  MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

  //Create and add a parameter to Parameters collection for the stored procedure.
  MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@au_lname", SqlDbType.VarChar, 40));

  //Assign the search value to the parameter.
  MyDataAdapter.SelectCommand.Parameters["@au_lname"].Value = (txtLastName.Text).Trim();

  //Create and add an output parameter to the Parameters collection. 
  MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@RowCount", SqlDbType.Int, 4));

  //Set the direction for the parameter. This parameter returns the Rows that are returned.
  MyDataAdapter.SelectCommand.Parameters["@RowCount"].Direction = ParameterDirection.Output;

  //Create a new DataSet to hold the records.
  DataSet DS = new DataSet();
  
  //Fill the DataSet with the rows that are returned.
  MyDataAdapter.Fill(DS, "AuthorsByLastName");

  //Get the number of rows returned, and assign it to the Label control.
  //lblRowCount.Text = DS.Tables(0).Rows.Count().ToString() & " Rows Found!"
  lblRowCount.Text = MyDataAdapter.SelectCommand.Parameters[1].Value + " Rows Found!";

  //Set the data source for the DataGrid as the DataSet that holds the rows.
  GrdAuthors.DataSource = DS.Tables["AuthorsByLastName"].DefaultView;

  //NOTE: If you do not call this method, the DataGrid is not displayed!
  GrdAuthors.DataBind();

  MyDataAdapter.Dispose(); //Dispose the DataAdapter.
  MyConnection.Close(); //Close the connection.
 }
     

12 October 2011

Get Multiple value from CheckedListbox in C#



Get Multiple value from CheckedListbox in C#

For Example:
 private void LoadSectionDetails()
        {
            try
            {
                DataTable dt;
                dt = objSectionDetailsBR.DisplayAll();

                if (dt.Rows.Count > 0)
                {
                    chbLSection.DataSource = dt;
                    chbLSection.DisplayMember = "SectionName";
                    chbLSection.ValueMember = "SectionID";
                }
           
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }


//To get the value member and display member in Checkedlistbox in C#


 foreach (var item in chbLSection.CheckedItems)
            {
                var row = (item as DataRowView).Row;
                int id = row.Field("SectionID");
                string name = row.Field("SectionName");
              //  MessageBox.Show(id + ": " + name);
            }

List in C#

List in C#


Namespace used:System.Collections.Generic
The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.


List<string> dinosaurs = new List<string>();
dinosaurs.Add("Tyrannosaurus");
dinosaurs.Add("Amargasaurus");
dinosaurs.Add("Mamenchisaurus");
dinosaurs.Add("Deinonychus");
dinosaurs.Add("Compsognathus");
foreach(string dinosaur in dinosaurs)
{
      Console.WriteLine(dinosaur);
}

 dinosaurs.Insert(2, "Compsognathus");//To Insert in List

 dinosaurs.Clear(); //To Clear


27 September 2011

Delete all Stored Procedure or SP in Sql Server


Delete all Stored Procedure or SP in Sql Server

DECLARE @procedureName varchar(500)
DECLARE cur CURSOR
      FOR SELECT [name] FROM sys.objects WHERE type = 'p'
      OPEN cur

      FETCH NEXT FROM cur INTO @procedureName
      WHILE @@fetch_status = 0
      BEGIN
            EXEC('DROP PROCEDURE ' + @procedureName)
            FETCH NEXT FROM cur INTO @procedureName
      END
      CLOSE cur
      DEALLOCATE cur

6 September 2011

Sql Server Queries - Disabled all Constrains,Drop all table,Enable all Constraints in Sql Server

--Disabled all constrains in sql server
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

--Drop all table in Database
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"


--Enable all constrains in sql server
exec sp_msforeachtable @command1="print '?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"

Disable and Enable Foreign key references in Sql Server 2008

Disable and Enable Foreign key references in Sql Server 2008

-- Disable all table constraints

ALTER TABLE MyTable NOCHECK CONSTRAINT ALL

-- Enable all table constraints

ALTER TABLE MyTable CHECK CONSTRAINT ALL

-- Disable single constraint

ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint

-- Enable single constraint

ALTER TABLE MyTable CHECK CONSTRAINT MyConstraint

5 September 2011

Redefine your image with these tips - Personality development

Apart from being strong in academics, honing your manners, etiquette and body language is also important. Rummy Sharma shares a few tips on the same. Read on. -Thanks yahoo India Education


Packaging, they say is the mantra for success these days. How you present yourself and tackle various situations goes a long way to set your image in the company of friends or in an organization. So if you are a school student entering college or a graduate taking a plunge in corporate world you, we suggest you get your soft skills right. Apart from academics, look at honing your manners, etiquette and body language, to have that extra edge over others.
In Y! Campus’s one hour chat with etiquette guru, Rummy Sharma we got some amazing tips for. Here are excerpts of the chat.
Q: Please suggest me some etiquette or way of behaving during personal interview during admission process for MBA which can impress the people on the panel. – Zohra
RS: Do these things: 1. Dress formally. 2. Check your tone of voice. 3. Watch your behavior. 4. Be aware of your visual communication. Prepare well not only with subject, but with your presentation of self.
Q: Sir, tell me the best way to shake hands while meeting anyone officially. - Arpana
RS: Hi Arpana, there are handshakes and more handshakes. One must stand straight, offer a firm hand, three pumps on a first official introduction, twice for subsequent meetings and one when leaving others. It is always the right of the lady to decide whether she wants to offer a handshake to a man or not and a very important rule is that, the host is the one who has to initiate the handshake.
Q: How loud a voice is considered etiquette for public meeting /conferences? - Jaya
RS: Hi Jaya, one doesn't need a loud voice these days to be a good public speaker. What with the audio equipment that is provided. Just speak as if you are talking to a group of six people around you. That should be fine.
Q: What kind of table manners should be followed when out for lunch with clients? – Reema
RS: Hi Reema, Dining table is the place where one can demonstrate their etiquette. Learn how to use the cutlery and crockery, their usage and a very important rule, you go to a restaurant not to eat but to show off your skill of western dining. Also ensure that you know the placement of crockery, cutlery, don't make mouth noises, practice cutting food and bringing it to the mouth. All your liquids will be on your right and solids on your left.
Q: How can I improve my impression and how can I be that kind of a person whom people like to help. What are the points I should keep in my mind? - Sanjeev
RS: Usually we say give and take respect. We believe that when we are helpful others will do the same to us. But sometimes we need to be assertive. Don't just go around doing good. You need to make it clear that you expect them to help you too and ask for it when needed.
Q: Please tell me the attitude, manners and personality traits which I should develop, which would be useful for me to face any sort of administrative/political-problems/solution or any complicated circumstances I come across in my future. N.Praveen Devaraaja
RS: Whether you will be a success or not depends on the first impressions you make on others. It just takes seven seconds time for somebody to come to form a first impression about you. So you need to be careful of how you are perceived by others. Also be natural in your presentation. To be successful, you need to analyze every situation and take a decision that is logical and serves the purpose.
Q: What is the best way to teach etiquette to the age group of 4 - 6 year old kids? - Kavita
RS: I say, kids have only eyes and no ears. They see what you do and how you practice what you preach. So teach the kids etiquette by practicing it.
Q: I’ve recently joined a MNC. I often don’t bother about what people think about me. I only concentrate on my business. Because of this my colleagues feel I have a bad attitude and they don’t interact with me as they would do with the other people. So give me some ideas that I could implement to get their attention and how to maintain the attitude, personality, manners in front of them. - Mohan C
RS: People are always observing us and come to conclusions about us by how we interact with them. If you really want to grow, you cannot do it on your own. You need to be a team player. So start smiling at them to start with and join the coffee machine conversations. Slowly, you will be accepted in to the team. Offer help and ask for help too occasionally.
Q: I wanted to know what should be my thoughts, my body language and my attitude. And how can I come out from my shyness and speak in front of a crowd. - Mohit Mudgal
RS: It is not only your problem but of millions of others. Practice talking in front of a mirror to start with. Practice with friends who would help you. Make a start.
Q: I'm from a village and have come to Mumbai. In first impression I look professional but when I start to speak with anyone they understand from my language that I’m from the village and they start to underestimate me. Then it creates problems for me to communicate in proper way. - Ram
RS: Your written communication is good. Improve your accent, and overcome your mother tongue influence. It will take time. But since you are already aware of your problem, you can overcome it.
Q: I want to know the right postures for a job interview. - Arpan
RS: Hi Arpan, sit with your back erect, arms on the armrest, hands on the lap. Do move your hands, head occasionally. Don't allow your elbows to creep on to the table in front of you. It is not yours.
Q: Is eye contact with the audience an essential factor while delivering a speech? – Nandini
RS: Hi Nandini, in the western culture which we are trying to imitate, eye contact is a must. Otherwise, people think we are not being honest. If you have a problem making constant eye contact, look between the eyes of the people. It will make you, and the other person comfortable.
Mr Rummy Sharma specializes in international business etiquette, soft skills and training for HR and non-HR professionals. He has come out with India’s first training video called ‘Manners Matter’. He has trained children as well as business etiquette to CEOs.

Implementing OAuth validation in a Web API

 I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...