title: Executing SQl Queries in C# using CLR
body: <p>I am using SQl CLR for parsing some table column. I want to execute the queries also in C# user defined function. Can somebody give an example to execute select and insert queries in the function?</p>
  
  <p>Thank you in advance.</p>
  
  <pre><code> SqlConnection objSqlConn;
      string connString = string.Empty;
      connString = "Data Source=(local);Initial Catalog=DB;User ID=uname;pwd=pass;Password=pass";
      objSqlConn = new SqlConnection(connString);
      objSqlConn.Open();
  
      string query = "Select count(*) FROM [DB].[dbo].[TableName]";
      SqlCommand cmdTotalCount = new SqlCommand(query, objSqlConn);
      cmdTotalCount.CommandTimeout = 0;
      string TotalCountValue = cmdTotalCount.ExecuteScalar().ToString();
      return TotalCountValue;
  </code></pre>