|
-
August 10th, 2008, 02:24 AM
#1
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
-
August 10th, 2008, 02:43 AM
#2
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
-
August 10th, 2008, 04:55 AM
#3
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.
-
August 10th, 2008, 08:04 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|