Sunday, May 30, 2010

How to Add rows to a database? using VB.NET?

Dim newcustrow As DataSetname.tablenameRow
newcustrow =Datasetname.Tablename.NewRow
          newcustrow.cust_name = TxtName.Text
          newcustrow.Address = TxtAddress.Text
DataSetname.tablename.Rows.Add(newCustrow)

Datasetname.Tablename.AcceptChanges()

Database handling (table updation) concepts!

http://msdn.microsoft.com/en-us/library/ms171932(v=VS.80).aspx

 

 

 

 

Source: http://msdn.microsoft.com/en-us/library/5ycd1034(v=VS.80).aspx

Increase the performance of you webpage! reducing the load-time!

http://developer.yahoo.com/performance/rules.html

Where do i get lots of java scripts and other helps?

1. http://www.scriptsearch.com/JavaScript/Scripts/

2. Background effects javascripts

http://www.scriptsearch.com/cgi-bin/jump.cgi?ID=1110

Save and restore form information using cookies

// -----------------------------------------------------//
// SAVE FORM FIELD SELECTIONS IN COOKIES         //
// formcookie_saverestore.js                //
// Written by Tony Davis, T. Davis Consulting, Inc.    //
// Date written: September 27, 2005            //
// Email: tony@tdavisconsulting.com            //
// Web site: http://www.tdavisconsulting.com        //
// -----------------------------------------------------//

// instructions:
// ------------
// Change <BODY>
// to <BODY onunload="saveSelections(document.forms[0])"> and
// Change </FORM>
// TO </FORM><SCRIPT language=JavaScript type="">loadSelections(document.forms[0]);</SCRIPT>
// see a working example at: http://www.tdavisconsulting.com/formcookie
//

//
// ------------------------------------------------
// This function will concatentate all the fields in
// in the form into one string, delimited by a PIPE
// symbol, into one cookie. The cookie name is the
// same name as the form name. ALL fields are saved.
// ------------------------------------------------
//

function saveSelections(frm) {
        var setvalue;
        var fieldType;
        var index;
        var formname = frm.name;

        // Expire cookie in 999 days.
        var today = new Date();
        var exp   = new Date(today.getTime()+999*24*60*60*1000);

        var string = "formname=" + formname + "|";
        var cookieName = formname;

        //alert(exp);
        //alert(formname);

        var n = frm.length;
        for (i = 0; i < n; i++)

        {
            e         = frm[i].name;
            fieldValue  = frm[i].value;
            fieldType   = frm[i].type;

            //alert(e);
            //alert(fieldType);
            //alert(fieldValue);

            //
            // RADIO BUTTON
            //
            if (fieldType == "radio") {
            //alert(frm.elements[e].length);
                for (x=0; x < frm.elements[e].length; x++) {
                    if (frm.elements[e][x].checked)
                    {
                    index = x
                    }
                }
            string = string + index + "\|";
            }

            //
            // TEXT, TEXTAREA, and DROPDOWN
            //
            if ((fieldType == "text") ||
                (fieldType == "textarea") ||
                (fieldType == "select-one"))
            {
                string = string + frm.elements[e].value + "\|";
                //alert("text");
            }

            //
            // CHECKBOX
            //
            if (fieldType == "checkbox")
            {
                if (frm.elements[e].checked==true) {
                    var setvalue = "1";
                    }
                if (frm.elements[e].checked==false) {
                    var setvalue = "0";
                    }
            string = string + setvalue + "\|";
            //alert("checkbox");
            }

            //
            // HIDDEN field
            //
            if (fieldType == "hidden")
            {
                string = string + frm.elements[e].value + "\|";
                //alert("text");
            }
        }

//alert(string);
setCookie(cookieName, string, exp); }

//
// LOAD FORM FIELD SELECTIONS FROM SAVED COOKIES
//

function loadSelections(frm) {
var e;
var z;
var x;
var cookieName;
var fieldArray;
var fieldValues;
var fieldValue;

var formname = frm.id;

// Retrieve form elements from cookie and split into array.

cookieName  = formname;
fieldValues = getCookie(cookieName);
fieldArray  = fieldValues.split("\|");

//alert(fieldArray);
//alert(fieldArray[0]);
//alert(fieldArray[1]);
//alert(fieldArray[2]);
//alert(fieldArray[3]);

        var n = frm.length;
        for (i = 0; i < n; i++) {
            e = frm[i].name;
            z = i;
            z++;
            var fieldType  = frm[i].type;
            var fieldValue = fieldArray[z];

            //
            // TEXT, TEXTAREA, and DROPDOWN
            //
            if ((fieldType == "text") ||
                (fieldType == "textarea") ||
                (fieldType == "select-one"))
            {
                frm.elements[e].value = fieldValue;
                //alert(e);
                //alert(fieldValue);
            }

            // CHECKBOX
            //
            if (fieldType == "checkbox")
            {
                fld_checkbox = fieldValue;
                if (fld_checkbox == "1") {
                    frm.elements[e].checked = true;
                }
            }

            // RADIO BUTTON
            //
            if (fieldType == "radio") {
                x = fieldValue;
                //alert(x);
                frm.elements[e][x].checked = true;
            }

            //
            // HIDDEN field
            //
            if (fieldType == "hidden")
            {
                frm.elements[e].value = fieldValue;
                }
        }
}

/// COOKIE FUNCTIONS

function setCookie(name, value, expires, path, domain, secure) {
document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}

 

 

source:http://javascript.internet.com/cookies/save-and-restore-form-cookies.html

passing variables between scripts on the same page

QUERY:

Hi,
I have a page with several javascripts in it. For some reason I can't
seem to pass variables between the scripts and I need to for one of
the functions.

I understand this can be done by giving each script a name and
referencing the script name with the variable.
Could you provide an example of this,
or another method of passing variables between scripts.


Solution: by declaring the variables globally



I believe I see your problem: like some other languages, JavaScript
has a notion of 'scope' (although quite a quite limited one in
comparison). If you declare a variable inside of one function is JS,
you can't use it in another function. The simple work around is to
declare all variables 'globally' (often considered bad style in other
languages, but pretty common in JS). Alternatively, you could make the
two helper functions return values and call them from calc, but the
other way is probably more straight forward for you. Make the
following simple change and your script should work:

<SCRIPT Type="text/javascript" Language="JavaScript">
<!--
var variable1; // declare the variables outside of the functions
var variable2;

function calc(){
var x = (variable1 / variable2);
}
function userInput1(){
variable1 = adb;
}
function userInput2(){
variable2 = arnd;
}
//-->
</SCRIPT>

How do i pass data between javascript pages?

Your JavaScript page has retrieved some information from the user. Now you want to display another JavaScript page, which should also use that information. How do you pass it from the first page to the second? There are three simple solutions. The first two are safe and effective, with advantages and disadvantages to each. The third appears ideal but has a very serious security problem and should be avoided.

1. Submitting form data to a server-side script that then outputs a new JavaScript page containing the data. This is simple and reliable and works in all browsers, but requires support for server-side scripting of some kind (PHP, ASP, etc).

2. Passing form-style data in a URL to a new JavaScript page, without using any server-side scripts. This works in all browsers but supports a limited amount of data. It is the traditional way of solving the problem without server-side scripting.

3. Passing data via the window.name property. Although this is not the intended purpose of window.name, it seems to work quite well and supports larger amounts of data than the second method. And it works in Safari, Firefox, and Internet Explorer

. So why not use it? Because it is highly insecure! If the user follows a link to another website that doesn't belong to you, that other website can still see the data stored in window.name, which was never meant to be a secure, site-specific property. So I strongly discourage the use of this method.

When possible, it's best to use the first method, because the amount of data you can pass is essentially unlimited. I'll demonstrate the first two methods and give an overview of the third, but as I said, the third is unsafe and you should not use it.

1. Using a Server-Side Script

When server-side scripting is available, this is the best approach. Let's assume you have a JavaScript array of strings you'd like to pass to a new web page:

<script>
var data = new Array();
data[0] = "one, a datum";
data[1] = "two, a deer";
data[2] = "three, a slash: \\";
data[3] = "four has quotes: \"I forget what four was for\"";
</script>

To pass this array to a script on a new page without packing it into a long URL (remember, URLs are limited to a practical maximum of 2,083 characters in the most popular web browser, and long URLs don't look very pretty either), we can use a hidden form in the first page, and submit this form to a PHP script on the server using the POST method. The GET and POST methods differ in that a GET-method form submission packs everything in the URL, which is nice for bookmarkable searches but a poor choice for large amounts of data. The POST method submits the data outside of the URL, without a length limit.

You could call the sendData function from any JavaScript code. Calling it when a link is clicked is simply one example.

We'll use a hidden field in the hidden form to pass the information. A hidden form field is a single string, so we'll pack the array into it by using a comma to separate elements of the array. And since the data might also contain commas, we'll use JavaScript's escape() function to encode these, so that they can't be confused with our separators. We'll name both the form and the hidden field within it data. When we do this, we access set the contents of the hidden field using the JavaScript syntax document.data.data.value (read from right to left: the value of the field named data, in the form named data, in the document).

the two listings that follow are passdata1a.html and passdata1b.php. passdata1a.html passes an array of JavaScript data to passdata1b.php when a link is clicked.

passdata1a.html

<script>
var data = new Array();
data[0] = "one, a datum";
data[1] = "two, a deer";
data[2] = "three, a slash: \\";
data[3] = "four has quotes: \"I forget what four was for\"";
</script>
<form name="data" method="POST" action="passdata1b.php">
<input type="hidden" name="data">
</form>
<script>
function sendData()
{
  // Initialize packed or we get the word 'undefined'
  var packed = "";
  for (i = 0; (i < data.length); i++) {
    if (i > 0) {
      packed += ",";
    }
    packed += escape(data[i]);
  }
  document.data.data.value = packed;
  document.data.submit();
}
</script>
<h1>This is what the array contains:</h1>
<ul>
<script>
  for (i = 0; (i < data.length); i++) {
    document.write("<li>" + data[i] + "</li>\n");
  }
</script>
</ul>
<a href="javascript:sendData();">Go to passdata1b.php</a>

passdata1b.php

<?php
  $packed = $_POST['data'];
  $data = split(",", $packed);
  for ($i = 0; ($i < count($data)); $i++) {
    # Undo what JavaScript's escape() function did
    $data[$i] = rawurldecode($data[$i]);
    # Slashes need escaping when they appear in code
    $data[$i] = str_replace("\\", "\\\\", $data[$i]);
    # Quotes need escaping too
    $data[$i] = str_replace("\"", "\\\"", $data[$i]);
  }
?>
<script>
  var data = new Array (
<?php
  for ($i = 0; ($i < count($data)); $i++) {
    if ($i > 0) {
      echo ",\n";
    }
    echo "    \"";
    echo $data[$i];
    echo "\"";
  }
?>
  );
</script>
<h1>This is what the data contains:</h1>
<ul>
<script>
  for (i = 0; (i < data.length); i++) {
    document.write("<li>" + data[i] + "</li>\n");
  }
</script>
</ul>

source http://www.boutell.com/newfaq/creating/scriptpass.html

Thursday, May 27, 2010

How to retrieve data from sql database( basic query)

suppose we have a database PAYROLL we have a table employee in database Payroll. following are the fields on which we will see all possible retrievals;

Empid Fname Lname Department Salary Unit

1 | ABD | KJH | dep1 |10000 | unit1

2 | DEF | DYTHG | dep2 |20000 | unit1

3 | GHI | GYUNBG | dep3 |40000 | unit2

4 | JKLM | IHIHJJU | dep4 |20000 | unit1

5 | NOPQW | GBTUNV | dep5 |10000 | unit3

6 | STUV | JHIUUV | dep6 |50000 | unit1

Command 1 : Select all entries from table

select * from payroll.employee

this command will give you whole table.

command 2: selecting only First name and Last name

select fname, lname from payroll.employee

defining user-defined column name: this can be done by following commands.

  • select ‘Department Name ‘= Department , ‘First Name’=fname, ‘Last Name’=Lname from payroll.employee
  • select Department ‘Department Name ‘ , fname ‘First Name’, Lname ‘Last Name’ from payroll.employee
  • select Department AS ‘Department Name ‘ , fname AS ‘First Name’, Lname AS ‘Last Name’ from payroll.employee

Now inserting the literals between the columns :

select empid, ‘ is the id of’, fname from payrol.employee

this command will give the following outtput:

Empid no column name Fname

1 | is the id of | ABD
2 | is the id of | DEF

3 | is the id of | GHI

4 | is the id of | JKLM

5 | is the id of | NOPQW

6 | is the id of| STUV

Wednesday, May 26, 2010

how do i send automated mail form my web application?


 Introduction.
At ISQsolutions it is required that all email messaging have to be authenticated, any attempt to send anonymous email will fail. To send email from your website you will need to configure your scripts to authenticate against your designated SMTP server (usually smtp.yourdomain.com or smtp.websoon.com) with one of your existent email accounts at ISQsolutions mail servers.
Sending emails in ASP.NET 2.0
// using System.Net.Mail;
// using System.Net;

SmtpClient smtpClient = new SmtpClient("smtp.domainHosted.com");

smtpClient.Credentials = new NetworkCredential("user1@domainHosted.com", "passwordHere");

MailMessage message = new MailMessage();

message.From = new MailAddress(user1@domainHosted.com);
message.To.Add(new MailAddress(nick@example.com));
message.To.Add(new MailAddress(ben@example.com));

message.Subject = "This is my subject";
message.Body = "This is the content";

smtpClient.Send(message);


- Sending mail from ASP via CDO object. ( What happened to CDONTS ? )
With the introduction of Windows Server 2003, Microsoft dropped support for CDONTS. Therefore, applications that use CDONTS do not function on Windows Server 2003, furthermore CDONTS does not provide the means to send email via authenticated SMTP.


These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.
References:
Microsoft Windows Server 2003 does not install CDONTS : http://support.microsoft.com/default.aspx?scid=kb;en-us;315197


- Sending mail from ASP with Persits ASPEmail object.
Consult the excellent documentation that Persits have put together at : http://www.aspemail.com/manual.html
Here is a short example:


These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.


- Sending mail from ASP.NET.

Here is a C# version.
// using System.Web.Mail;
MailMessage eMail = new MailMessage();
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "account@domainHosted.com";
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "password";
eMail.To = "someone@yahoo.com"; // Recipients
eMail.From = "somebody@yahoo.com";
eMail.Subject = "This is the subject line";
eMail.Body = "Test Message";
SmtpMail.SmtpServer = "smtp.domainHosted.com";
SmtpMail.Send(eMail);
And a VisualBasic version
Dim eMail = new MailMessage()
eMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
eMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "account@domainHosted.com"
eMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

eMail.To = "someone@yahoo.com"
eMail.From = "somebody@yahoo.com"
eMail.Subject = "This is the subject line"
eMail.Body = "Test Message"
SmtpMail.SmtpServer = "smtp.domainHosted.com"
SmtpMail.Send(eMail)

These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.
- Sending mail from PHP.

This sample uses the Pear Mail package. The package is already in the INCLUDE path.
http://pear.php.net/package/Mail
include_once("Mail.php");
$recipients = 'mail_to@domain.mail';
$headers["From"] = 'mail_from@domain.mail';
$headers["To"] = 'mail_to@domain.mail';
$headers["Subject"] = "Test message";
$body = "TEST MESSAGE!!!";
$params["host"] = 'smtp.domainHosted.com';
$params["port"] = "25";
$params["auth"] = true;
$params["username"] = 'account@domainHosted.com';
$params["password"] = "password";
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory("smtp", $params);
$mail_object->send($recipients, $headers, $body);
echo "Email sent."
?>

These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.


- Setting up a Form to Mail script.
To set-up a very easy form to mail script you may download the following script. To configure it follow the instructions inside the formmail.asp file.

Monday, May 17, 2010

How to populate dataset using a data adapter in vb.net?

 
OleDbDataAdapter provides the communication between the Dataset and the Data Source with the help of OleDbConnection Object . The OleDbConnection Object has no information about the data it retrieves . Similarly a Dataset has no knowledge of the Data Source where the data coming from. So the OleDbDataAdapter manage the communication between these two Objects.
The OleDbDataAdapter object allows us to populate Data Tables in a DataSet. We can use Fill method of the OleDbDataAdapter for populating data in a Dataset. The following source codeshows a simple program that uses OleDbDataAdapter to retrieve data from Data Source with the help of OleDbConnection object and populate the data in a Dataset.
Imports System.Data.OleDb Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connetionString As String Dim connection As OleDbConnection Dim oledbAdapter As OleDbDataAdapter Dim ds As New DataSet Dim i As Integer connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;" connection = New OleDbConnection(connetionString) Try connection.Open() oledbAdapter = New OleDbDataAdapter("Your SQL Statement Here") oledbAdapter.Fill(ds) oledbAdapter.Dispose() connection.Close() For i = 0 To ds.Tables(0).Rows.Count - 1 MsgBox(ds.Tables(0).Rows(i).Item(0)) Next Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class

How to connect, retrieve data from SQL server using VB.net?


"




SqlDataAdapter provides the communication between the Dataset and the Data Source with the help of SqlConnection Object . The SqlConnection Object has no information about the data it retrieves . Similarly a Dataset has no knowledge of the Data Sourcewhere the data coming from. So the SqlDataAdapter manage the communication between these two Objects. The TableMapping Collections help the SqlDataAdapter to do this task.
The InsertCommand, the UpdateCommand, and the DeleteCommand properties of the SqlDataAdapter object update the database with the data modifications that are run on a DataSetobject. The following source code demonstrate how to update a Dataset through SqlDataAdapter using a DataGridView. For running this source code , open a new VB.NET project and drag two buttons and a DataGridView in the default form1 and copy and paste the following Source Code.

Imports System.Data.SqlClient
Public Class Form1
    Dim connetionString As String
    Dim connection As SqlConnection
    Dim adapter As SqlDataAdapter
    Dim cmdBuilder As SqlCommandBuilder
    Dim ds As New DataSet
    Dim changes As DataSet
    Dim sql As String
    Dim i As Int32

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
        connection = New SqlConnection(connetionString)
        Sql = "select * from Product"
        Try
            connection.Open()
            adapter = New SqlDataAdapter(Sql, connection)
            adapter.Fill(ds)
            connection.Close()
            DataGridView1.Data Source= ds.Tables(0)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            cmdBuilder = New SqlCommandBuilder(adapter)
            changes = ds.GetChanges()
            If changes IsNot Nothing Then
                adapter.Update(changes)
            End If
            MsgBox("Changes Done")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

see source webpage
  

A few first words frm my side...

This blog hosts some good quality code that i found over the net! this is for intermediate level and thus might contain some occasional descriptions...but i still stick to my title...straight code...No bullshit!
i'll try to mention the source website...so that you can explore. i don't intend to make profit from this blog ( in terms of monetary gains). but i also will keep referring to this blog when i need help till i get all the codes on my tips...thatz nearly impossible since i am very bad at that. lolz cya :D