Tuesday, January 29, 2013

Enter only Numeric Data in TextBox


private void TxtQuantity_KeyPress(object sender, KeyPressEventArgs e)
        {
if (char.IsDigit(e.KeyChar) == false && char.IsLetter(e.KeyChar) == false && char.IsControl(e.KeyChar) == false && e.KeyChar != '.' && e.KeyChar != ' ')
            {
                e.Handled = true;
                MessageBox.Show("You can enter only number.", "KenCloud", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TxtQuantity.Clear();
                TxtQuantity.Focus();
                return;
            }
}

Enter only Numeric data in Datagridview in c#


private void DgviewStock_CellEndEdit(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 10))
            {
                string value = DgviewStock.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                foreach (char c in value)
                {
                    if (!char.IsDigit(c))
                    {
                        MessageBox.Show("Please enter numeric value.");
                        DgviewStock.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty;
                        return;
                    }
                }
            }
        }

Common Report Viewer for All CrystalReport


namespace Barcodes.Reports
{
    public partial class frmReportViewer : Form
    {
        public string paramvalue;
        public int reportFlag,paramvalueId;

        public frmReportViewer( )
        {
            InitializeComponent();
       
        }

        private void frmReportViewer_Load(object sender, EventArgs e)
        {

            TAGGING_CommonVariable objVar = new TAGGING_CommonVariable();
            objVar.servername = @"SATYA";
            objVar.DatabaseName = "Admission";
            objVar.username = "sa";
            objVar.password = "sql";        

            if (reportFlag == 0)//IssueToQualityControl
            {
                crReport objCr = new crReport();               
                CrystalDecisions.Shared.TableLogOnInfo tliCurrent = default(CrystalDecisions.Shared.TableLogOnInfo);
                try
                {
                    foreach (CrystalDecisions.CrystalReports.Engine.Table tbCurrent in objCr.Database.Tables)
                    {
                        tliCurrent = tbCurrent.LogOnInfo;
                        var _with1 = tliCurrent.ConnectionInfo;
                        _with1.ServerName = objVar.servername;
                        _with1.DatabaseName = objVar.DatabaseName;                      
                        _with1.UserID = objVar.username;
                        _with1.Password = objVar.password;
                        _with1.IntegratedSecurity = false;
                        tbCurrent.ApplyLogOnInfo(tliCurrent);
                    }

                    this.crystalReportViewerAll.ReportSource = objCr;
                    objCr.SetParameterValue(0, paramvalue);
                    objCr.SetParameterValue(1, paramvalueId);
                    crystalReportViewerAll.Show();

                }                 

                catch
                {
                }

            }
             }
}

Case sensitive for Sql select in Sql Server



Create PROCEDURE  SelectDetails
(
@Name varchar(30)
)
AS
BEGIN

    if (select name from  Student where Name=@Name ) is NULL
begin

SELECT       Name, Age ,Address    FROM   Student where Name=@Name
COLLATE  SQL_Latin1_General_CP1_CS_AS

        end