Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
H

hamed vojdani

@hamed vojdani
About
Posts
10
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Keyword not supported: 'initial catalogue'.
    H hamed vojdani

    hi, first initial catalog not initial catalogue :) second Initial Catalog and AttachDbFilename tags are ways to specify database place if use Initial Catalog mean that database is on server which Data Source tag says and connection must be opened toward database which it's name is in Initial Catalog and if use AttachDbFilename we specified physical place of database file if database file is on local machine and is not attached to local SQL server use AttachDbFilename else use Initial Catalog :thumbsup:

    C# help security

  • C# Data link to another PC?
    H hamed vojdani

    My offer ,else use MSDASC class now see what is my offer.. 1- Server side: Run Sql Server browser Service in your database server machine, then create Valid login for your database,set sql server authentication to Windows and SQL athentication 2- Application side: with a form like this: http://privateimage.com/images/9fq89vuk7uokjz8koz.jpg and with functions like below for buttons

        private void btnSearch\_Click(object sender, EventArgs e)
        {
            SqlDataSourceEnumerator SqlEnumerator = SqlDataSourceEnumerator.Instance;
            DataTable dt = new DataTable();
            dt = SqlEnumerator.GetDataSources();
            dataGridView1.DataSource = dt.DefaultView;
        }
    
    
        private void btnSave\_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 0)
            {
                string ConString = "";
    
                SqlConnectionStringBuilder builder =new SqlConnectionStringBuilder();
                builder.ApplicationName = "MyApp";
                builder.WorkstationID = Environment.MachineName;
                builder.UserID = txtLoginName.Text.Trim();
                builder.Password = txtPassword.Text.Trim());
                builder.InitialCatalog="MyDBName";                
                builder.DataSource = dataGridView1.SelectedRows\[0\].Cells\["ServerName"\].Value.ToString()+
               "\\\\"+dataGridView1.SelectedRows\[0\].Cells\["InstanceName"\].Value.ToString();
                
                ConString = builder.ConnectionString;
                
            }
           
        }
    

    at the end your data link string is ConString variable, you can store it in encrypted file or registry. each time application start check stored connection, and if failed retry this form note: used namespace are: using System.Data.Sql; using System.Data.SqlClient; hope helps with ugly sample ;)

    modified on Friday, December 25, 2009 9:45 AM

    C# question csharp database sysadmin security

  • C# Creating a class and assigning properties to it.
    H hamed vojdani

    I don't understand your question completely but this may be help :) 1- C# is case sensitive , mean that double Radius; and public double radius are not same. 2- Properties is not variable, it's a way for set or get a variable , and variable can be different type from it's properties like:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace circle
    {
    class circle
    {
    double Radius;
    public string radius
    {
    get
    {
    return Radius.ToString();
    }
    set
    {
    double i = -1;
    if (double.TryParse(value, out i))
    {
    Radius = i;
    }
    }
    }

        public string Circumference
        {
            get
            {
                return (2 \* Math.PI \* Radius).ToString("N6");
            }
        }
    }
    
    class MyApp
    {
        public static void Main()
        {
            circle myCircle = new circle();
            myCircle.radius = Console.ReadLine();
    
            Console.WriteLine("Radius: = {0}", myCircle.radius);
            Console.WriteLine("Circumference: = {0}", myCircle.Circumference);
    
        }
    }
    

    }

    3- Properties is not only for return existing variable, it can do process for calculating or formatting return value like Circumference properties in above code 4- Properties can be readonly like Circumference properties which you can not set a value for it Hope helps with this ugly sample code ;)

    C# csharp help question linq

  • Encrypting & decrypta txt file
    H hamed vojdani

    thanks you forget the "\\" before "MYFILE.txt" corrct that to this:

    FileStream fs = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\\\MYFILE.txt", FileMode.Create, FileAccess.ReadWrite);
    
    C# csharp help

  • Encrypting & decrypta txt file
    H hamed vojdani

    just insert button on the form and double click it, Then write button1_Click event code like shown. In this sample I encoded text of TextBox1 to 'Myfile.dat' in My Document note: must copy Encode function to Form class

        private void button1\_Click(object sender, EventArgs e)
        {
            Encode(TextBox1.Text);
        }
    
        public void Encode(string text)
        {
            byte\[\] array = Encoding.UTF8.GetBytes(text);
            FileStream fs = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\\\MyFile.dat", FileMode.Create, FileAccess.ReadWrite);
            GZipStream gstream = new GZipStream(fs, CompressionMode.Compress);
            gstream.Write(array, 0, array.Length);
            gstream.Flush();
            gstream.Close();
        }
    

    modified on Thursday, December 24, 2009 10:23 AM

    C# csharp help

  • Encrypting & decrypta txt file
    H hamed vojdani

    because you want both Encrypting and Decrypting I would offer you gunzipstream

        public string Decode()
        {
            FileStream fs = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\\\MyFile.dat", FileMode.Open, FileAccess.ReadWrite);
            byte\[\] array = new byte\[400\];
            GZipStream gstream = new GZipStream(fs, CompressionMode.Decompress);
            gstream.Read(array, 0, array.Length);
            gstream.Close();
            string Mytext = Encoding.UTF8.GetString(array);
            return Mytext;
        }
    
        public void Encode(string text)
        {
            byte\[\] array = Encoding.UTF8.GetBytes(text);
            FileStream fs = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\\\MyFile.dat", FileMode.Create, FileAccess.ReadWrite);
            GZipStream gstream = new GZipStream(fs, CompressionMode.Compress);
            gstream.Write(array, 0, array.Length);
            gstream.Flush();
            gstream.Close();
        }
    

    note: this solution is not completely secure!

    C# csharp help

  • datagridview
    H hamed vojdani

    Hi, add a ButtonColumn to DataGridView and name it like Colremove then write code for dataGridView CellContentClick event like shown below

        private void dataGridView1\_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                if (e.ColumnIndex == dataGridView1.Columns\["dataGridView1.Colremove"\].Index)
                {
                    dataGridView1.Rows.RemoveAt(e.RowIndex);
                }
    
            }
        }
    

    modified on Friday, December 18, 2009 1:55 PM

    C# question

  • C# Excel: Creating a named range?
    H hamed vojdani

    You can Create list of Range insted

        List<Range> myrng = new List<Range>(20);
        myrng.Add(excelWorksheet.get\_Range("A1", "B3"));
    

    and for one cell use Range like this:

    Range rng1 = excelWorksheet.get_Range("A1", "A1");

    then set property of each in loop

    C# question csharp tutorial

  • How to convert List to datatable
    H hamed vojdani

    What type of list? For list of int you can do it like this:

            List<int> myList = new List<int>(100);
            for (int i = 1; 1 <= 50; i++)
            {
                myList.Add(i);
            }
    
            // Create DataTable without column and row
            DataTable dt = new DataTable("MyTbl"); 
    
            // Add an integer Column
            dt.Columns.Add("MyColumn", Type.GetType("System.Int32")); 
            
            for (int j = 0; j < myList.Count; j++) // fill DataTable 
            {
                dt.Rows.Add(myList\[j\]);
            }
    
    C# help tutorial question

  • Help For "Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on."
    H hamed vojdani

    hi add this line to main function to disable CrossThread checks: Control.CheckForIllegalCrossThreadCalls = false; like this:

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        \[STAThread\]
        static void Main()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
    
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
    
    C# com help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups