How to change dataset column name in ASP.NET C#?

by Evgelen 22. March 2010 23:07

ds.Tables[0].Columns[0].ColumnName = "ColumnName";

Tags: , , ,

ASP.NET | C#

ASP.NET, C# - Convert string to array - Array to DataSet

by Evgelen 13. February 2010 18:17
                const string stringName = "keyword1, keyword2, keyword3";
                string[] arrayName = stringName.Split(',');

                var ds = new DataSet();
                var dt = new DataTable("Table_Name");
                ds.Tables.Add(dt);

                var dc = new DataColumn("Column_Name");
                dt.Columns.Add(dc);

                for (var i = 0; i <= arrayName.Length - 1; i++)
                {
                    var dr = dt.NewRow();
                    dr["Column_Name"] = keyw[i];
                    dt.Rows.Add(dr);
                }

                controlName.DataSource = ds;
                controlName.DataBind();

Tags: , , , , ,

ASP.NET | C# | DataSet | Array

Error: Debugging Failed Because Integrated Windows Authentication Is Not Enabled

by Evgelen 14. January 2010 22:00

Error: Debugging Failed Because Integrated Windows Authentication Is Not Enabled

Authentication of the user requesting debugging could not be done due to an authentication error when attempting to step into a Web application or XML Web service. One cause of this error is that integrated Windows authentication is not enabled. To enable it, perform the following steps. If you have enabled integrated Windows authentication and this error still appears, then it is possible that this error is caused because Digest Authentication for Windows Domain Servers is enabled. In this situation you should consult with your network administrator. To enable integrated Windows authentication

  1. Log onto the Web server using an administrator account.
  2. On the Start menu, click Administrative Tools Control Panel.
  3. In the Administrative Tools window, double-click Internet Information Services.
  4. In the Internet Information Services window, open the Web server node. A Web Sites folder opens beneath the server name.
  5. You can configure authentication for all Web sites or for individual Web sites. To configure authentication for all Web sites, right-click the Web Sites folder and click Properties on the shortcut menu. To configure authentication for an individual Web site, open the Web Sites folder, right-click the individual Web site, and on the shortcut menu, click Properties.
  6. In the Properties dialog box, click the Directory Security tab.
  7. In the Anonymous access and authentication control section, click the Edit button.
  8. In the Authentication Methods dialog box, under Authenticated access, select Integrated Windows authentication.
  9. Click OK to close the Authentication Methods dialog box.
  10. Click OK to close the Properties dialog box.
  11. Close the Internet Information Services window.

Tags: , ,

ASP.NET | C# | JavaScript | SQL | Error

Removes all occurrences of white space characters from the beginning and end of this instance.

by Evgelen 21. December 2009 06:07

String.Trim Method () Removes all occurrences of white space characters from the beginning and end of this instance.

[C#] 
using System;

public class TrimTest {
    public static void Main() {

        string [] temp = MakeArray();

        Console.WriteLine("Concatenating the inital values in the array, we get the string:");
        Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine);

        // trim whitespace from both ends of the elements
        for (int i = 0; i < temp.Length; i++)
            temp[i] = temp[i].Trim();

        Console.WriteLine("Concatenating the trimmed values in the array, we get the string:");
        Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine);

        // reset the array
        temp = MakeArray();

        // trim the start of the elements. Passing null trims whitespace only
        for (int i = 0; i < temp.Length; i++)
            temp[i] = temp[i].TrimStart(null);

        Console.WriteLine("Concatenating the start-trimmed values in the array, we get the string:");
        Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine);

        // reset the array
        temp = MakeArray();

        // trim the end of the elements. Passing null trims whitespace only
        for (int i = 0; i < temp.Length; i++)
            temp[i] = temp[i].TrimEnd(null);

        Console.WriteLine("Concatenating the end-trimmed values in the array, we get the string:");
        Console.WriteLine("'{0}'", String.Concat(temp));
    }

    private static string [] MakeArray() {
        string [] arr = {"  please    ", "  tell    ", "  me    ", "  about    ", "  yourself    "};
        return arr;
    }
}

Tags: , , ,

ASP.NET | C#

ASP.NET C# Bind DropDownList Control from SQL Datasource

by Evgelen 4. December 2009 20:03

ASP.NET C# Bind DropDownList Control from SQL Datasource

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

private void Page_Load(object sender, EventArgs e)
        {
            DropDownListBind();
        }

        public void DropDownListBind()
        {
            var conn = new SqlConnection
              {
                 ConnectionString =
                                   ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()
              };

            var cmd = new SqlCommand("SELECT * FROM TableName", conn);
            cmd.Connection.Open();

            var dropDownListsValues = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            DropDownListControl.DataSource = dropDownListsValues;
            DropDownListControl.DataValueField = "ControlId";
            DropDownListControl.DataTextField = "ControlData";
            DropDownListControl.DataBind();

            cmd.Connection.Close();
            cmd.Connection.Dispose();
        }


private void Page_Load(object sender, EventArgs e)
        {
            DropDownListBind();
        }

        public void DropDownListBind()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            using (var conn = new SqlConnection(connectionString))
            {
                var cmd = new SqlCommand("SELECT * FROM TableName", conn);
                cmd.Connection.Open();
                var dropDownListsValues = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                DropDownListControl.DataSource = dropDownListsValues;
                DropDownListControl.DataValueField = "ControlId";
                DropDownListControl.DataTextField = "ControlData";
                DropDownListControl.DataBind();
            }
        }

Tags: , , ,

ASP.NET | C# | SQL

Tag cloud