Tuesday, 29 March 2016

Excel Integer value upload time going wrong like 10000000..1e+9 or exponential format --Vasu

private void Uploaddata(string strConn, string[] columnNames, string strProcedure)
    {
        try
        {
            DataTable dataTableForTheAdapter = new DataTable();
           
            DataTable dtNew = new DataTable();
            string commaSepColumns = string.Empty;
            foreach (string strColumn in columnNames)
            {
                commaSepColumns = commaSepColumns + "," + strColumn;
                dtNew.Columns.Add(strColumn, typeof(String));
            }
            commaSepColumns = commaSepColumns.Substring(1, commaSepColumns.Length - 1);
            DataSet myDataSet = new DataSet();
            OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT " + commaSepColumns + " FROM [Sheet1$]", strConn);
            myCommand.Fill(dtNew);
           
            int j = 0;
            if (dtNew.Rows.Count > 0)
            {
                string consString = getSqlConnectionstring();
                using (SqlConnection con = new SqlConnection(consString))
                {
                    using (SqlCommand cmd = new SqlCommand(strProcedure))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Connection = con;
                        cmd.Parameters.AddWithValue("@tblCustomers", dtNew);
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();

                        lblDispMsg.Text = "Master data uploaded successfully.";
                    }
                }
            }
            else
            {
                lblDispMsg.Text = "Master data not uploaded as Data is not proper in Excel.";
            }
           
        }
        catch (Exception ex)
        {

            lblDispMsg.Text = "Error in File Upload.<br/>" + Convert.ToString(ex.Message);
       
        }
    }

Monday, 7 March 2016

Find Query string value by Name

 function querySt(Key) {

            var url = window.location.href;

            KeysValues = url.split(/[\?&]+/);

            for (i = 0; i < KeysValues.length; i++) {

                KeyValue = KeysValues[i].split("=");

                if (KeyValue[0] == Key) {

                    return KeyValue[1];

                }

            }

        }

        function GetQString(Key) {

            if (querySt(Key)) {

                var value = querySt(Key);

                return value;

            }

        }

        alert(GetQString("case"))

Friday, 5 February 2016

Select Date, DDL Date, Custome Validation in Csharp .net


 <script type="text/javascript">
 function CustDateValidator_ServerValidate(sender, args) {
            var dateString = document.getElementById("ddlday").value + "/" + document.getElementById("ddlmonth").value + "/" + document.getElementById("ddlYear").value;
            var regex = /(((0[1-9])|([1-31]))\/([1-9])|(0[1-9])|(1[0-2]))\/((19|20)\d\d)$/;
               if (regex.test(dateString)) {
                var parts = dateString.split("/");
                var dt = new Date(parts[1] + "/" + parts[0] + "/" + parts[2]);
                args.IsValid = (dt.getDate() == parts[0] && dt.getMonth() + 1 == parts[1] && dt.getFullYear() == parts[2]);
            } else {
                args.IsValid = false;
            }
        }
 </script>
<%
protected void CustDateValidator_ServerValidate(object source, ServerValidateEventArgs args)
    {
        DateTime dt;
        //ddlYear
        DateTime dtc;
        args.IsValid = false;
        try
        {
            dtc = Convert.ToDateTime(ddlYear.SelectedValue + "/" + ddlmonth.SelectedValue + "/" + ddlday.SelectedValue);
            args.IsValid = true;
        }
        catch (Exception)
        {

            args.IsValid = false;
        }


    }
%>

 <asp:DropDownList ID="ddlYear" runat="server"  ClientIDMode="Static"  AutoPostBack="true" OnSelectedIndexChanged="ddlYearchange">
                                    <asp:ListItem Value="0" Selected="True">YYYY</asp:ListItem>
   </asp:DropDownList>
  <asp:DropDownList ID="ddlmonth" runat="server"  ClientIDMode="Static" AutoPostBack="true" OnSelectedIndexChanged="ddlmonthchange">
                                    <asp:ListItem Value="0" Selected="True">MM</asp:ListItem>
   </asp:DropDownList>
 <asp:DropDownList ID="ddlday" runat="server" ClientIDMode="Static" AutoPostBack="true" OnSelectedIndexChanged="ddldaychange">
                                    <asp:ListItem Value="0" Selected="True">DD</asp:ListItem>
   </asp:DropDownList>


  <asp:CustomValidator runat="server" ID="CustDateValidator" OnServerValidate="CustDateValidator_ServerValidate"
                                ClientValidationFunction="CustDateValidator_ServerValidate"  CssClass="errorMsg" ErrorMessage="Please select valid date"
                                ValidationGroup="Vg" />

Wednesday, 3 February 2016

WCF Test Without Project

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
WcfTestClient.exe




Tuesday, 22 December 2015

The remote server returned an error: (400) Bad Request. using (WebResponse resp = req.GetResponse())

try
        {
            HttpWebRequest req = WebRequest.Create(UnitInfoServiceUrl) as HttpWebRequest;
            req.Credentials = new NetworkCredential("", "");
            req.KeepAlive = false;
            string result;
            using (WebResponse resp = req.GetResponse())
            {
                using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
                {
                    result = reader.ReadToEnd();

                }
            }
        }
        catch (WebException e)
        {
            using (WebResponse response = e.Response)
            {
                HttpWebResponse httpResponse = (HttpWebResponse)response;
                Response.Write(string.Format("Error code: {0}", httpResponse.StatusCode));
                using (Stream data = response.GetResponseStream())
                using (var reader = new StreamReader(data))
                {
                    string text = reader.ReadToEnd();
                    Response.Write(text);
                  dynamic stuff1 = JsonConvert.DeserializeObject(text);
                  string Error = stuff1.ERROR;
                    Response.Write(Error );
                }
            }
         
        }

Date and Time picker different formate

http://xdsoft.net/jqplugins/datetimepicker/

Friday, 11 December 2015

print function for particular div in js

function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

<div id="printableArea">
      <h1>Print me</h1>
</div>

<input type="button" onclick="printDiv('printableArea')" value="print a div!" />