Friday, 28 March 2014

To start autoincrement field from 1 in sqlserver.

To reset autoincrement value from 1 in sql server:


Step1: In query Designer write this Query
Syntax:
DBCC CHECKIDENT('DATABASENAME.DBO.TABLENAME',RESEED,number)


Eg:DBCC CHECKIDENT('DATABASENAME.DBO.TABLENAME',RESEED,0)

Step 2: Click on Execute.

After this query will executed our autoincremented field will start from 1.

If number=0 then the autoincrement value will start from 1. if number=101 then the autoincrement field will start from 102.

Thank You......

Wednesday, 26 March 2014

Open DataReader Error.......

Error:- There is already an open DataReader associated with this command which must be closed first.

Solution:

If we use datareader in if else condition and we close the reader in if condition then also this error occurs so the solution is write below code in your else condition

if (!reader.IsClosed)
                    {
                        reader.Close();
                    }

error solved.....

Saturday, 22 March 2014

To find Current Auto increment Value in Table.

string que = "Select IDENT_CURRENT('Table Name')"; //It will return Last Identity Value in your table

To fetch last id from table and to show one incremented value in textbox

SqlCommand cmdtxt = new SqlCommand();
        cmdtxt = new SqlCommand("SELECT pur_id FROM pur_productdb ORDER BY pur_productid DESC", con);
        SqlDataReader reader11 = cmdtxt.ExecuteReader();
        reader11.Read();
        txtpurid.Text = (Convert.ToInt16(reader11["pur_id"]) + 1).ToString();
        reader11.Close();

Wednesday, 12 March 2014

To Show only Time in Textbox

string dt=system.datetime.now.tostring("hh:mm:ss tt");
DateTime time=convert.toDateTime(dt);
time=time.addHours(2);

Textbox1.text=time.tostring("hh:mm:ss);

Redirect when click on RadioButton


 protected void btnsubmit_Click(object sender, EventArgs e)
 {
     if(RadioButton1.checked)
     {
             Response.redirect("payment.aspx");
      }
else if(RadioButton2.checked)
      {
            Response.redirect("sales.aspx");
        }
    }

Hyperlink in gridview

<asp:hyperlink id="hview" runat="server" text="view" navigateurl='<%#"~pageredirect.aspx?id="+eval("id")%>'> </asp:hyperlink>

Tuesday, 11 March 2014

textbox validation using javascript


 <script language="javascript" type="text/javascript">
        function validate() {

            var summary = "";
            summary += isvaliduser();
            summary += isvalidfirstname();
            summary += isvalidlocation();
            if (summary != "") {
                alert(summary);
                return false;
            }
            else {
                return true;
            }
        }
        function isvaliduser() {
            var uid;
            var temp = document.getElementById("<%=txtuser.ClientID %>");
            uid = temp.value;
            if (uid == "") {
                return ("Please Enter Username" + "\n");
            }
            else {
                return "";
            }
        }
        function isvalidfirstname() {
            var uid;
            var temp = document.getElementById("<%=txtfname.ClientID %>");
            uid = temp.value;
            if (uid == "") {
                return ("please enter firstname" + "\n");
            }
            else {
                return "";
            }
        }
        function isvalidlocation() {
            var uid;
            var temp = document.getElementById("<%=txtloc.ClientID %>");
            uid = temp.value;
            if (uid == "") {
                return ("Please enter Location" + "\n");
            }
            else {
                return "";
            }
        }
    </script>