Saturday, April 27, 2013

Sql Server: How to copy a table?


This is the simplest way to copy a table into another (new) table in the same SQL Server database. This way of copying does not copy constraints and indexes.



select * into [destination table] from [source table]
Example:
Select * into employee_backup from employee
We can also select only a few columns into the destination table like below

select col1, col2, col3 into [destination table]from [source table]
Example:
Select empId, empFirstName, empLastName, emgAge into employee_backup from employee
Use this to copy only the structure of the source table.

select * into [destination table] from [source table] where 1 = 2
Example:
select * into employee_backup from employee where 1=2
Use this to copy a table across two database in the same Sql Server.





select * into [destination database.dbo.destination table] from [source database.dbo.source table]
Example:
select * into Mydatabase2.dbo.employee_backup
from mydatabase1.dbo.employee

Use this to copy a table across two database in the same Sql Server.

select * into [destination database.dbo.destination table]
from [source database.dbo.source table]
 
Example:
select * into Mydatabase2.dbo.employee_backup
from mydatabase1.dbo.employee

Wednesday, April 10, 2013

NUMBER VALIDATION IN VB.NET

How to give number validate in textbox
take keypress event of textbox

Private Sub Txtqty_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Txtqty.KeyPress
Dim i As String = e.KeyChar.ToString
If i = " " Then
Else
If IsNumeric(i) Then
Else
e.Handled = True
MessageBox.Show("Enter valid Number")
End If
End If
End Sub

Tuesday, April 9, 2013

How To Store and retrive ConnectionString from app.config file in vb.net project

[?xmlversion="1.0"encoding="utf-8"?]
[configuration]
[connectionStrings]
[addname="MyDatabase"connectionString="Data Source=server;Initial Catalog=database;
User ID=userid;Password=password"providerName="System.Data.SqlClient"/][/connectionStrings]
[appSettings>[addkey="SomeSetting"value="Value1"/]
[addkey="SomeOtherSetting"value="Value2"/]
[/appSettings]
[/configuration] To access the connection string  you use this code:

Dim myConnString AsString = ConfigurationManager.ConnectionStrings("MyDatabase")
Be sure to add a reference to System.Configuration.dll and add Imports System.Configuration to your code.

Multi-Statement Transactions with Rollback Statement

Begin Tran
insert into usertest(user1)values('sandeep')
insert into usertest1(name)values('lko')
insert into usertest2(fname)values('delhi')
if @@rowcount =1
commit Tran
else
Rollback Tran

Monday, April 8, 2013

SQL String Functions > Concatenate


SQL Server:
SELECT region_name + ' ' + store_name FROM Geography
WHERE store_name = 'Boston';



Table Geography

region_namestore_name
EastBoston
EastNew York
WestLos Angeles
WestSan Diego

Result:
'East Boston'

Sunday, April 7, 2013

Generating Random Numbers

Double-click on the button to write its code.
Type in this code:
Private Sub Cmdrandom_Click()
For i = 0 To 9
Randomize
Txtrandom.Text = Format(((Rnd(i) * 100) + 1), "0")
Next i
End Sub

Friday, April 5, 2013

Java Script for Confirm Box or (yes/no) box

Look At :-
[input id="Button3" onclick="return confirm('Are You Sure?');" type="button" value="button" />]
Eg.

Sending Email From Your Gmail Account in vb.net

Use these namespace and add function to your event on which you want to send email.
*****************************************************************
Imports System.Web
Imports System.Net
Imports System.Net.Mail

Public Function sndmail()
Try

 Dim client As New SmtpClient()
               Dim sendTo As New MailAddress("email of other person")
                Dim from As MailAddress = New MailAddress("youremail")
                Dim message As New MailMessage(from, sendTo)
                message.IsBodyHtml = True
                message.Subject = "Mail subject"
                message.IsBodyHtml = True
                Dim st As String = "Your Mail Body "              
                message.Body = st
                message.IsBodyHtml = True
                Dim basicAuthenticationInfo As New System.Net.NetworkCredential("yourfullemail", "password")
                client.Host = "smtp.gmail.com"
                client.UseDefaultCredentials = False
                client.Credentials = basicAuthenticationInfo
                client.EnableSsl = True
                client.Send(message)

         Catch ex As Exception
            Response.Write("")
        End Try
End Function

******************************************************************

Print A Web Page Javascript

It is just a small function name window.print() you need to call on a button click:-
[input type="button" name="Print" value="Print" onclick="window.print();" /]

Reset All Text Box in windows Form

Public Sub ClearTextBox(ByVal root As Control)
        For Each ctrl As Control In root.Controls
            ClearTextBox(ctrl)
            If TypeOf ctrl Is TextBox Then
                CType(ctrl, TextBox).Text = String.Empty
            End If
        Next ctrl



write the
 ClearTextBox(Me)
under click on reset button