|
|
Hi expert ,
this is login code with Mysql Connectivity .it is not working.
no error is showing
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace ExampleOne
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void btnlogin_Click(object sender, EventArgs e)
{
string g_login = this.tbUsername.Text;
string g_password = this.tbpassword.Text;
string MyConString = "server=localhost;database=password;uid=root;password=asd";
MySqlConnection connection = new MySqlConnection(MyConString);
string Strsql = "select * from tablogin where userid = ' " + g_login + " 'AND password=' " + g_password + " ' ";
MySqlCommand command = new MySqlCommand(Strsql, connection);
MySqlDataReader Reader;
try
{
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string auser;
string apwd;
auser = (Reader[g_login].ToString());
apwd = (Reader[g_password].ToString());
if (auser == g_login && apwd == g_password)
{
MessageBox.Show("INCORRECT USER/PASS!");
}
else
{
MessageBox.Show("YOU ARE LOGGED IN!");
}
}
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error Conecting to database", "window information" + ex.Message.ToString(),
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
|
|
|
|
|
Your code is really, really crappy. I can erase your database any time I like. Apart from that, hard to say, given that you don't tell us what code executes, what you see, what happens, etc. Do you know how to use the debugger ? Any execution path should show a message box, so more detail than 'it's not working' should be easy to offer, even if you don't know how to debug code.
Also, the right way to check a login is to do a select count(*), not to get the username and password returned.
Oh, I see the issue.
ashish1nov2008 wrote: while (Reader.Read())
So, if nothing is returned, you won't see anything. Duh.
ashish1nov2008 wrote: else
{
MessageBox.Show("YOU ARE LOGGED IN!");
}
This can never execute, by definition.
Look at your SQL, make sure what you're typing in is correct ( for example, is there a trailing space in the DB and not in your text ? Can you think of ways to make that not matter ?
I think you need to read a basic C# book and start again.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Ooops SQL Injection
string Strsql = "select * from tablogin where userid = ' " + g_login + " 'AND password=' " + g_password + " ' ";
This is How you Should do it
First you have to Create a Storedprocure that counts the Records that match the username and password,
Create Procedure prclogin_check
(
@User_name varchar(20),
@U_Password varchar(23),
@Results int Output
)
IF EXISTS (Select * from User_Table
where User_name =@User_name and U_Password = @U_Password)
Set @Results =1
And after you are done with this , you have to do the Following in your C# Code
using System.Data.SqlClient;
String strcon = "User id = sa;Password= topman;Server=myServer;Database=MyDB";
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandTimeout = 0;
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = con;
cmdselect.CommandText = "prclogin_check";
cmdselect.Parameters.Add("@Results",SqlDbType.Int,4);
cmdselect.Parameters["@Results"].Direction = ParameterDirection.Output;
int Res;
try
{
con.Open();
cmdselect.ExecuteNonQuery();
Res = (int)cmdselect.Parameters["@Results"].Value;
con.Close();
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}using System.Data.SqlClient;
String strcon = "User id = sa;Password= topman;Server=myServer;Database=MyDB";
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandTimeout = 0;
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = con;
cmdselect.CommandText = "prclogin_check";
cmdselect.Parameters.Add("@Results",SqlDbType.Int,4);
cmdselect.Parameters["@Results"].Direction = ParameterDirection.Output;
int Res;
try
{
con.Open();
cmdselect.ExecuteNonQuery();
Res = (int)cmdselect.Parameters["@Results"].Value;
con.Close();
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}
And in your Business logic or in your Form you can create a Function that will test if the Count of Records is greater than 0,if its less than that , then its invalid login
Hope this Helps
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswam@its.co.za
|
|
|
|
|
hi, i looked up googles and everywhere.. but i couldn't solve the problem
this is my codes.
since i searched the gooles, lots of people say if you have "GetResponse() hang" it's because you didn't close the Response. but this cann't be my situation. Because, in my case, a timer has to run every 5 seconds so i can't do
" Response.close()". does anybody have any ideas??
[STAThread]
public static void Main(string [] args)
{
Application.Run(new HealthMon());
}
private void HealthMon_Load(object sender, System.EventArgs e)
{
this.CheckTimer.Interval = 5000;
this.CheckTimer.Start();
}
private void CheckTimer_Tick(object sender, System.EventArgs e)
{
System.Net.WebRequest request = null;
System.Net.HttpWebResponse response = null;
try
{
request = System.Net.WebRequest.Create("http://url.....");
response = (System.Net.HttpWebResponse)request.GetResponse();
GlobalProxySelection.Select = WebProxy.GetDefaultProxy();
if(response.StatusCode != HttpStatusCode.OK)
{
MessageBox.show("error");
}
else
{
MessageBox.show("success");
}
}
catch( Exception ex )
{
MessageBox.show("error");
}
}
|
|
|
|
|
Chances are if GetResponse() hangs, you have not recieved a response. Try putting in some different urls and see what happens. Also, have you configured your proxy correctly?
Regards,
Rob Philpott.
|
|
|
|
|
I have tried diffrent urls.. like localhost, and the other PC that is right next to me..
and I don't have proxy settings..
they all hangs... -_-
|
|
|
|
|
Don't know then. I've tried your code slightly modified (below) and it works fine. Suspicion turns to the timer. If you call this just once from Main rather than repeatedly, does it work?
public static void Main(string[] args)
{
System.Net.WebRequest request = null;
System.Net.HttpWebResponse response = null;
request = System.Net.WebRequest.Create("http://news.bbc.co.uk");
WebProxy p = new WebProxy("...our proxy", true);
p.UseDefaultCredentials = true;
request.Proxy = p;
response = (System.Net.HttpWebResponse)request.GetResponse();
}
Regards,
Rob Philpott.
|
|
|
|
|
yes! it only works for 2times.
the third time... hangs.. -_-
sometimes it goes more then two times, but the result is the same eventually..
|
|
|
|
|
Then something isn't clearing up properly. Are you using a Windows Forms timer? I'm wondering if the Response stream needs to be disposed or something. Will have a play...
Regards,
Rob Philpott.
|
|
|
|
|
I've managed to reproduce it, it hangs on the second time. As I just eluded to, its because your response stream doesn't get disposed.
Stick this after you call GetResponse() and I think you'll be ok:
response.GetResponseStream().Dispose();
Regards,
Rob Philpott.
|
|
|
|
|
#define P 0x8408
main()
{
register unsigned int b, v;
register int i;
printf("typedef unsigned short u16;\n");
printf("static u16 fcstab[256] = {");
for (b = 0; ; ) {
if (b % 8 == 0)
printf("\n");
v = b;
for (i = 8; i--; )
v = v & 1 ? (v >> 1) ^ P : v >> 1;
printf("\t0x%04x", v & 0xFFFF);
if (++b == 256)
break;
printf(",");
}
printf("\n};\n");
}
===> C# ?!?
|
|
|
|
|
Actually, it would look pretty much the same, except that you would replace printf with Console.WriteLine
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
<code>
static int Main()
{
//C++ TO C# CONVERTER NOTE: 'register' variable declarations are not supported in C#:
//ORIGINAL LINE: register uint b, v;
uint b;
uint v;
//C++ TO C# CONVERTER NOTE: 'register' variable declarations are not supported in C#:
//ORIGINAL LINE: register int i;
int i;
Console.Write("typedef unsigned short u16;\n");
Console.Write("static u16 fcstab[256] = {");
for (b = 0;
{
if (b % 8 == 0)
Console.Write("\n");
v = b;
for (i = 8; i--;)
v = v & 1 ? (v >> 1) ^ DefineConstants.P : v >> 1;
Console.Write("\t0x{0:x4}", v & 0xFFFF);
if (++b == 256)
break;
Console.Write(",");
}
Console.Write("\n};\n");
}
internal sealed class DefineConstants
{
public const int P = 0x8408;
}
</code>
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
VB & C# to Java Converter
Java to VB & C# Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB, C#, or Java to C++
|
|
|
|
|
Is there some sort of black magic to keep code snippets from being butchered here?
The 'code' tags don't appear to actually do anything and even though I un-selected 'auto-encode...', I still get the ridiculous emoticons...
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
VB & C# to Java Converter
Java to VB & C# Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB, C#, or Java to C++
|
|
|
|
|
Hi all,
One of my server application I've log all information into text files, on my own pattern.
For ease of use I'm going to write an application to analyze the log. What I'm looking to do is, read the text file line-by-line and match some strings. Depends on that validation doing different process and display, may be on a UI.
Is that way is effective. Comments are really appreciate.
Thanks
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi,
you can use regular expressions to match the strings. For defining different processes depending on that validation I would suggest using the strategy pattern.
Should the logfile analysed only once? If not you have to find a mechanism so that you knwo which line you already read and which not.
Regards
Sebastian
|
|
|
|
|
Hi,
Thanks for commenting
Actually log file analyze only once. Later I want to compare two logs, say for socket and internal process something.
I've think about one thing. Read the whole file once and store all line in a collection framework. But I want to choose which is the best.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Wll reading the whole one file once and storing them in a collection will be very memory and time consuming I think. If this is not a problem for you then go on, but if it is... depending on the comparison you want to do I would try sth with reading line by line (without storing) etc.
|
|
|
|
|
Hi
I advance thanks for ur help.....i am developing send SMS from PC to Multiple recipients using C# application.shall you help me.Give me how to i proceed this project further,i am a Final year MCA Student...
Thankyou
G.Thenmozhi
|
|
|
|
|
I think there are no differences between one or multiple recipients.
For example, if you want to send it using mobile phones, which connected to PC, you must use class SerialPort, if the mobile phone is connected to serial port.
The AT command for sending SMS, you can find it, for example if you use Nokia phone, then find it in Nokia website. There is a PDF document about Nokia AT command.
|
|
|
|
|
oviyaa wrote: am a Final year MCA Student...
But you don't know how to use a search engine ?
There is no built in SMS support, so you need to find a library that supports it. Which makes your project a joke, all you will do is call some SDK that you didn't write. Choose something else. This time, not at random, but based on what you know how to do, and will make your teachers happy.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi Thenmozhi,
We shaal help you , but can you tell us where are you stuck (any exception or bug ) or are you still to start , if that the case than you need to decide one way out of the following ways available.
There are few options to select from when it comes to sending an SMS to multiple user using your computer , i would list few of them
1) You can use SMS Gateways , there are many gateways (websites) available which allows to send sms at nominal rate , you need to go to this websites , register , buy credit , they provide you with set of function which you can use and send SMS , it is different for different providers ,for list of such providers you can google "SMS Gateways".
2) The second way is to connect your mobile phone to the computer and send SMS (you can connect you phone to computer using comm port ) when the SMS is send it is routed through your mobile , to send SMS using your phone you need to use AT command set. Your phone has a GSM modem in it (most of the phone have) this modem understand commands called as AT commands , using this command set you can send SMS through your phone from your PC , there are many controls available to do this stuff , but if you dont want to purchase it and write the code by our self you have to learn few AT commands (not very hard) and serial port programming (again it is not very hard ). Here is an example, also you can goolge "Sending SMS using GSM Modem" or "Sending SMS using AT command set" to get more info on this.
http://www.codeproject.com/KB/IP/Sending_SMS_using_Net.aspx[^]
3) There are GSM modem available in market , which comes with the software to send SMS to multiple recipient (please confirm this with the vendor before purchasing one) , this kind of device cost you in the range of 100$-200$ , and is easily available.
This is all for now , let me know if you require any further details.
-Regards
Bharat Jain
bharat.jain.nagpur@gmail.com
|
|
|
|
|
if (SMSPort.IsOpen == true)
{
SMSPort.WriteLine("AT" + (char)(13));
SMSPort.ReadLine();
Delay(3000);
if (SMSPort.ReadLine().Contains("OK"))
{
SMSPort.WriteLine("AT+CMGS=" + strRPhNo + (char)(13));
Delay(2000);
SMSPort.WriteLine(" " + strALL + (char)(26));
do
{
Delay(100);
if (SMSPort.ReadLine().Contains("OK"))
{
SMSPort.WriteLine("ATQ0" + (char)(13));
return true;
}
}
while(iTmeOut<10) ;
SMSPort.WriteLine("ATQ0" + (char)(13));
strErrLog = "Message Not Send " + DateTime.Now;
return false;
}
else
{
SMSPort.WriteLine("ATQ0" + (char)(13));
strErrLog = "Modem not Reponding" + DateTime.Now;
return false;
}
}
else
{
strErrLog = "Port is Closed" + DateTime.Now;
return false;
}
}
this part of code may help
|
|
|
|
|
SMSPort = new SerialPort();
SMSPort.PortName = COMMPORT;
SMSPort.BaudRate = 4800;
SMSPort.Parity = Parity.Even;
SMSPort.DataBits = 7;
SMSPort.StopBits = StopBits.One;
SMSPort.Handshake = Handshake.RequestToSend;
SMSPort.DtrEnable = true;
SMSPort.RtsEnable = true;
SMSPort.NewLine = System.Environment.NewLine;
|
|
|
|
|