Help with Numeric Only Textbox

Discussion in 'C#' started by jkessous, Aug 10, 2008.

  1. jkessous

    jkessous New Member

    Joined:
    Aug 10, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi All,
    I have some small problem with adding a function that will allow only numbers into the text box.
    Can someone help?

    Thanks alot.

    Here is the code

    Code:
     
    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms; 
    using Sybase.Data; 
    using Sybase.Data.AseClient; 
    
    namespace SID_Checker 
    { 
    public partial class Form1 : Form 
    { 
    public Form1() 
    { 
    InitializeComponent(); 
    } 
    
    private void panel1_Paint(object sender, PaintEventArgs e) 
    { 
    
    } 
    
    private void label1_Click(object sender, EventArgs e) 
    { 
    
    } 
    
    
    private void button1_Click(object sender, EventArgs e) 
    { 
    
    string ID = SID.Text; 
    
    if (ID == "" || ID == "0" || ID == null) 
    { 
    label4.Text = "Are you Kidding Me"; 
    return; 
    } 
    
    // <--> Sybase Connection String and Query <--> 
    
    AseConnection oAseConn = new AseConnection(); 
    oAseConn.ConnectionString = "Data Source=10.161.56.162;" + 
    "Port=2024;" + 
    "User ID=dbs;" + 
    "Password=password"; 
    oAseConn.Open(); 
    
    AseCommand getsid = oAseConn.CreateCommand(); 
    getsid.CommandText = "select SID_num from Sessions where sid = " + ID; 
    Object obj = getsid.ExecuteScalar(); 
    
    
    AseCommand getname = oAseConn.CreateCommand(); 
    getname.CommandText = "select code from SID_info where SID_num = " + obj; 
    Object targetname = getname.ExecuteScalar(); 
    
    label4.Text = targetname.ToString(); 
    getsid.Dispose(); 
    oAseConn.Dispose(); 
    
    } 
    
    private void SID_TextChanged(object sender, EventArgs e) 
    { 
    
    } 
    } 
    } 
    
    
    P.S
    I tried using the following but it either did nothing or gave me an error.
    Please help me place it at the right place in my code.
    thanks

    Code:
    private void textBox1_KeyPress(object sender, KeyPressEventArgs e) 
    { 
    if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)Keys.Back) 
    e.Handled = true; 
    } 
    
    thanks
    Jonny
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice