Hi all;
I am using MySQl with C#. And I have configured the odbc for MySQL.
I am having a problem in it.
MySQL table is as follows
Database name :- test
Table Name :- Login
Attributes :-1. login
2. pwd
Program structure is as follows:-
I have a text box named usrText and other named pwdText
When I write username in usrText then I want to match its value in my
database and want to retrieve pwd with that username from my database.
then I am matching that passwrod which is fetched from the database to
one which is enterred in the pwdText and if matching happens then I
wnat an output in third textbox named logText which is in the bottom
of the form.
please check it I am not getting any output. It is my first program in
which I am making connectivity with database.
the code is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
namespace Login
{
public partial class Form1 : Form
{
private System.Data.Odbc.OdbcConnection OdbcCon;
private System.Data.Odbc.OdbcCommand OdbcCom;
private System.Data.Odbc.OdbcDataReader OdbcDr;
private string ConStr;
//private string ComStr;
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
private void button1_Click(object sender, EventArgs e)
{
ConStr = "DRIVER={MySQL ODBC 5.1
Driver};SERVER=127.0.0.1;PORT=3306;DATABASE=test;UID=root;PWD=vikas;OPTION=3";
OdbcCon = new System.Data.Odbc.OdbcConnection(ConStr);
logText.AppendText("Creating Connnection\r\n");
try
{
OdbcCon.Open();
string chk = usrText.Text;
logText.AppendText(chk+"\r\n");
//ComStr = "Select login,pwd From login where login =
chk";
string query = "SELECT pwd FROM login WHERE login =
chk";
//OdbcCom = new System.Data.Odbc.OdbcCommand("insert
login (login, Pwd) values('raj','raj');");
OdbcCom = new System.Data.Odbc.OdbcCommand(query);
//string abc = OdbcCom.Connection.ToString();
logText.AppendText(OdbcCom.ToString);
}
catch {}//(System.Data.Odbc.OdbcException Ex)
{ logText.AppendText(Ex.Message + "\r\n"); }
}
private void pwdText_TextChanged(object sender, EventArgs e)
{
}
private void usrText_TextChanged(object sender, EventArgs e)
{
}
private void logText_TextChanged(object sender, EventArgs e)
{
}
}
}