Monday 5 November 2012

Send mail from asp.net

How to send mail from asp page ?? Here is the solution. ..
  we are using google mail [gmail] credentials for send mails from our page. before use the code you must specify the following header 
   using System.Net.Mail;


try
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("frommail@gmail.com");
            mail.To.Add("Tomail@gmail.com");
            mail.Subject = "Test Mail";
            mail.Body ="Test Mail";

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);
           
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }


use the code and enjoy your mailing .............. :)

Friday 26 October 2012

Connet C#.net with SQL server 2008 with dsn

Hi. Guys,
   Create a dsn with name "dsnApp".

Add  following code to your program.cs file


         try
            {
               OdbcConnection conDb=new OdbcConnection();
                string strsql ;
                strsql = "Provider=MSDASQL.1;DSN=dsnApp;UID=sa;pwd=app;";
                conDb.ConnectionString = strsql;
                conDb.Open();
           }
            catch(Exception ex)
           {
               MessageBox.Show(ex.ToString());
            }
                                                                                 If you are using VB.net your code is here

Thank you :)


Monday 27 February 2012

Fill Combobox using dataset in VB.net


                         If You have a combobox1 in a form (“Form 1”) and a database in SQL server  with a table,  named “tblCountry”  having  fields “countryID”, ”countryName” with data then  you can strat from here..... :)
Because, we fill combobox with Country with its id,


For database connection using dsn

We are using odbc connection , So we must import odbc class file first into the form(“Form 1”),

Imports System.Data.Odbc

Create a sub function in your form

Public Sub FillMaComboBox()

        Dim sqlQury As String
        sqlQury = "select countryID, countryName from tblCountry" 

        Dim ds As New DataSet
        Dim odbda As New OdbcDataAdapter(sqlQury, conDb) ‘conDb is connection object
        odbda.Fill(ds) ‘Fill selected data to ds(our dataset) using OdbcDataAdapter

        ComboBox1.DataSource = ds.Tables(0).DefaultView
        ComboBox1.DisplayMember = “countryName” ‘We want to display country
        ComboBox1.ValueMember = “countryID” ‘We store id as valueMember of ComboBox

End Sub



Now you did it bro.,
You can use this “ FillMaComboBox() into any event handler that you want….:)




Thursday 16 February 2012

Thread in VB.net

This is a simple App for Demonstrate threading in VB.net
   Add
          1) ListBox 1,ListBox 2
          2)Button1(Start Thread)
                                       To our Form (Form1)
Now we are ready for coding ..... :)


  • Import "System.threading" to our thread App
        Import System.Threading
  • Create  Sample functions in app called "FillList1" and "FillList2"
        Private Sub FillList1()
       for i as integer=0 to 25
           ListBox1.Items.Add(i)
           Threading.Thread.Sleep(1000) 'To visible working of threads
       next i
     End Sub
     Private Sub FillList2()
       for j as integer=0 to 25
           ListBox2.Items.Add(j)
           Threading.Thread.Sleep(1000)
       next i
     End Sub
  • Now we call our sample threads from our start Button (Button1)
     Private Sub Button1_Click(ByVal sender As System.Object,_
                        ByVal e As System.EventArgs)Handles Button1.Click

        Dim thrd1 As Threading.Thread   'Declare thread1 named as thrd1

        Dim thrd2 As Threading.Thread   'Declare thread2 named as thrd2

        Control.CheckForIllegalCrossThreadCalls=False 'Avoid Illegal thread call

        thrd1=New Threading.Thread(AddressOf FillList1)  

        thrd2=New Threading.Thread(AddressOf FillList2)

        thrd1.Start()

        thrd2.Start()
End Sub

Now run your App.......:D
 

Monday 2 January 2012

Connection in vb.net with dsn


Create a connection with vb.net to SQL server through dsn,

"Try
                Dim strsql As String
                strsql = "Provider=MSDASQL.1;DSN=dsnTest;UID=sa;"
                conDb.ConnectionString = strsql
                conDb.Open()
Catch exConnection As Exception
                MsgBox(exConnection.Message)
End Try"