CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2008
    Posts
    9

    Help with Numeric Only Textbox

    Hi All,
    I am a noob in programing
    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 to use this but either i got an error or nothing happens.
    Please see if you can help me place it on the correct place in my code.

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

    Thanks alot for the support
    Jonny

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Help with Numeric Only Textbox

    Edit your first post to remove the password and IP address. That won't help us, but can hurt you.

    Not sure why you're using ! and || and &&

    You should be using OR, AND, or, NOT (|| && !) i think
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Help with Numeric Only Textbox

    You should be using OR, AND, or, NOT (|| && !) i think
    This is the C# forum : OR, AND and NOT don't exist in C#. Did you get lost DG ?

    In response to the question : have you read this ?

    Darwen.

    P.S. Well done on using code tags !
    Last edited by darwen; August 10th, 2008 at 04:58 AM.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  4. #4
    Join Date
    Aug 2008
    Posts
    9

    Re: Help with Numeric Only Textbox

    Thanks alot guys,
    i got it working finally.
    i added another line in the code that was missing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured