Wednesday, April 10, 2013
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:
[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
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_name | store_name |
East | Boston |
East | New York |
West | Los Angeles |
West | San 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
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.
[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
******************************************************************
*****************************************************************
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();" /]
[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
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
Tuesday, February 19, 2013
Delete Data in Grid View
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Partial Class admin_student
Inherits System.Web.UI.Page
Public cn As SqlConnection
Public da As SqlDataAdapter
Public Function fillgrid()
cn = New SqlConnection("Data Source=;Initial Catalog=;User ID=;Password=")
da = New SqlDataAdapter("select * from s_reg", cn)
ds = New DataSet()
da.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
End Function
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
cn = New SqlConnection("Data Source=;Initial Catalog=;User ID=;Password=")
da = New SqlDataAdapter("select * from s_reg", cn)
Dim cmd As SqlCommandBuilder = New SqlCommandBuilder(da)
ds = New DataSet
da.Fill(ds)
ds.Tables(0).Rows(e.RowIndex).Delete()
da.Update(ds)
GridView1.DataSource = ds
GridView1.DataBind()
End Sub
Thursday, June 7, 2012
Message Box In Vb.net

Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ' ' First show a single-argument dialog box with MessageBox.Show. ' MessageBox.Show("Dot Net Perls is awesome.") ' ' Show a two-argument dialog box with this method. ' MessageBox.Show("Dot Net Perls is awesome.", _ "Important Message") ' ' Use a three-argument dialog box with MessageBox.Show. ' ... Also store the result value in a variable slot. ' Dim result1 As DialogResult = MessageBox.Show("Is Dot Net Perls awesome?", _ "Important Question", _ MessageBoxButtons.YesNo) ' ' Use four parameters with the method. ' ... Use the YesNoCancel enumerated constant and the Question icon. ' Dim result2 As DialogResult = MessageBox.Show("Is Dot Net Perls awesome?", _ "Important Query", _ MessageBoxButtons.YesNoCancel, _ MessageBoxIcon.Question) ' ' Use five arguments on the method. ' ... This asks a question and you can test the result using the variable. ' Dim result3 As DialogResult = MessageBox.Show("Is Visual Basic awesome?", _ "The Question", _ MessageBoxButtons.YesNoCancel, _ MessageBoxIcon.Question, _ MessageBoxDefaultButton.Button2) ' ' Use if-statement with dialog result. ' If result1 = DialogResult.Yes And _ result2 = DialogResult.Yes And _ result3 = DialogResult.No Then MessageBox.Show("You answered yes, yes and no.") ' Another dialog. End If ' ' Use MessageBox.Show overload that has seven arguments. ' MessageBox.Show("Dot Net Perls is the best.", _ "Critical Warning", _ MessageBoxButtons.OKCancel, _ MessageBoxIcon.Warning, _ MessageBoxDefaultButton.Button1, _ MessageBoxOptions.RightAlign, _ True) ' ' Show a dialog box with a single button. ' MessageBox.Show("Dot Net Perls is super.", _ "Important Note", _ MessageBoxButtons.OK, _ MessageBoxIcon.Exclamation, _ MessageBoxDefaultButton.Button1) End Sub End Class
Monday, May 21, 2012
Rounded-Corners for Table
.rounded-corners
{
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
-khtml-border-radius: 20px;
border-radius: 20px;
background:#CC0000;
width :40%;
}
OR
write In table Tag
style="border-radius:15px"
Monday, May 14, 2012
upload Image in Gridview vb.net
Import System.IO
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Try
Dim s As String = FileUpload1.PostedFile.FileName
Dim s1 As String = Path.GetFileName(s)
FileUpload1.PostedFile.SaveAs(Server.MapPath("img/" + s1))
Dim s2 As String = "../img/" + s1
da = New SqlDataAdapter("insert into move(title,director)values('" + TextBox1.Text + "','" + s2 + "')", cn)
ds = New DataSet()
da.Fill(ds)
GridView2.DataSource = ds
GridView2.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Try
Dim s As String = FileUpload1.PostedFile.FileName
Dim s1 As String = Path.GetFileName(s)
FileUpload1.PostedFile.SaveAs(Server.MapPath("img/" + s1))
Dim s2 As String = "../img/" + s1
da = New SqlDataAdapter("insert into move(title,director)values('" + TextBox1.Text + "','" + s2 + "')", cn)
ds = New DataSet()
da.Fill(ds)
GridView2.DataSource = ds
GridView2.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Wednesday, May 2, 2012
Textbox with background image using CSS
.searchBox{
background-image
:
url
(
'images/magnifying-glass.gif'
);
background-repeat
:
no-repeat
;
padding-left
:
20px
;
}
Member login |
Tuesday, May 1, 2012
Get Text and Value of Selected Item of ASP.Net RadioButtonList using jQuery
[head>
[script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
[script type="text/javascript">
$("#demo").live("click", function () {
var selectedItem = $("[id*=RadioButtonList1] input:checked");
if (selectedItem.length > 0) {
alert("Selected Value: " + selectedItem.val() + " Selected Text: " + selectedItem.next().html());
} else {
alert("Please select an item.");
}
});
[/script>
[/head>
[body>
[form id="form2" runat="server">
[asp:RadioButtonList ID="RadioButtonList1" runat="server">
[asp:ListItem Text="One" Value="1" />
[asp:ListItem Text="Two" Value="2" />
[asp:ListItem Text="Three" Value="3" />
[/asp:RadioButtonList>
[br />
[input type = "button" id = "Button1" value = "Demo" />
[/form>
[/body>
[/html>
Monday, April 30, 2012
how to make single radio button selection in gridview using javascript
[head id="Head1" runat="server">
[title>Grdview with Arraylist
[style type="text/css">
.Gridview
{
font-family:Verdana;
font-size:10pt;
font-weight:normal;
color:black;
width:300px;
}
[/style>
[script language="javascript" type="text/javascript">
function SelectSingleRadiobutton(rdbtnid) {
var rdBtn = document.getElementById(rdbtnid);
var rdBtnList = document.getElementsByTagName("input");
for (i = 0; i < rdBtnList.length; i++) {
if (rdBtnList[i].type == "radio" && rdBtnList[i].id != rdBtn.id)
{
rdBtnList[i].checked = false;
}
}
}
[/script>
[/head>
[body>
[form id="form1" runat="server">
[div>
[asp:GridView ID="gvdata" runat="server" CssClass="Gridview" AutoGenerateColumns="false" DataKeyNames="UserId" HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White">
[Columns>
[asp:TemplateField>
[ItemTemplate>
[asp:RadioButton id="rdbUser" runat="server" OnClick="javascript:SelectSingleRadiobutton(this.id)" />
[/ItemTemplate>
[/asp:TemplateField>
[asp:BoundField DataField="UserName" HeaderText="Name"/>
[asp:BoundField DataField ="FirstName" HeaderText="FirstName" />
[asp:BoundField DataField="LastName" HeaderText="LastName" />
[asp:BoundField DataField="Location" HeaderText="Location" />
[/Columns>
[/asp:GridView>
[/div>
[/form>
[/body>
[/html>
how to calculate age of person and regular expression for mm/dd/yyyy format using JavaScript
[script type="text/javascript"]
function CalculateAge(birthday)
{
var re=/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/;
if (birthday.value != '') {
If (re.test(birthday.value)) Then
{
birthdayDate = new Date(birthday.value);
dateNow = new Date();
var years = dateNow.getFullYear() - birthdayDate.getFullYear();
var months=dateNow.getMonth()-birthdayDate.getMonth();
var days=dateNow.getDate()-birthdayDate.getDate();
if (isNaN(years)) {
document.getElementById('lblAge').innerHTML = '';
document.getElementById('lblError').innerHTML = 'Input date is incorrect!';
return false;
}
else {
document.getElementById('lblError').innerHTML = '';
document.getElementById('lblAge').innerHTML = years +' Years ' +months +' months '+days +' days';
}
}
else
{
document.getElementById('lblError').innerHTML = 'Date must be mm/dd/yyyy format';
return false;
}}}
[/script]
[/head>
[body>
[form id="form1" runat="server">
[div>
Date of Birth :
[span style="color: Red">
[asp:Label ID="lblError" runat="server">
[br />
Age : [span id="lblAge">
[/div>
[/form>
[/body>
[/html>
How to disable right click on asp.net web page using JavaScript | Disable mouse right click on webpage
[script language="JavaScript" type="text/javascript"]
//Message to display whenever right click on website
var message = "Sorry, Right Click have been disabled.";
function click(e) {
if (document.all) {
if (event.button == 2 || event.button == 3) {
alert(message);
return false;
}
}
else {
if (e.button == 2 || e.button == 3) {
e.preventDefault();
e.stopPropagation();
alert(message);
return false;
}
}
}
if (document.all) {
document.onmousedown = click;
}
else {
document.onclick = click;
}
[/script]
[/head]
[body]
[form id="form1" runat="server"]
[div]
[/div]
[/form]
[/body]
[/html]
Saturday, April 28, 2012
Watermark Extender
[asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server"
TargetControlID ="textw" WatermarkText ="Enter Name Please"]
[/asp:TextBoxWatermarkExtender]
[asp:TextBox ID="textw" runat="server"][/asp:TextBox]
Monday, April 23, 2012
Difference between where and having clause
1. The WHERE clause specifies the criteria which individual records must meet to be selcted by a query. It can be used without the GROUP BY clause. The HAVING clause cannot be used without the GROUP BY clause.
2. The WHERE clause selects rows before grouping. The HAVING clause selects rows after grouping.
3. The WHERE clause cannot contain aggregate functions. The HAVING clause can contain aggregate functions.
The HAVING clause allows you to filter the results of aggregate functions,
such as COUNT() or AVG() or SUM(), or MAX() or MIN(), just to name a few.
HAVING provides you a means to filter these results in the same query,
as opposed to saving the results of a WHERE clause SQL statement to a temporary table
and running another query on the temporary table results to extract the same results.
Subscribe to:
Posts (Atom)