🔒 Closed My basic codes (pasok)

Status
Not open for further replies.

DeepFlex

Fanatic
Share ko lang itong mga naipon kung codes sobrang basic lang po nito. :)


LOGIN

string con = "datasource=localhost;port=3306;username=root;password=admin";
string query = "SELECT count(*) FROM stamonica.login WHERE USERNAME='" + textBox1.Text + "' AND PASSWORD= '" + textBox2.Text + "';";
MySqlConnection connect = new MySqlConnection(con);
MySqlCommand cmd = new MySqlCommand(query, connect);
MySqlDataReader read;
try
{
connect.Open();
read = cmd.ExecuteReader();
int count = 0;
while (read.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Success");
main ss = new main();
ss.Show();
this.Hide();
}
else if (count > 1)
{
MessageBox.Show("Incorrect password");
}
else
{

MessageBox.Show("Incorrect");
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


HOW TO SAVE


if (txtname.Text != "" && txtlast.Text != "" && txtmi.Text != "" && cbogender.Text != "" && txtage.Text != "" && cbograde.Text != "" && cbosection.Text != "" && txtstudentid.Text != "")
{
string con = "datasource=localhost;port=3306;username=root;password=admin";
string query = "INSERT INTO stamonica.student(Name,Lastname,MI,Gender,Age,Grade,Section,StudentID) VALUES('" + txtname.Text + "','" + txtlast.Text + "','" + txtmi.Text + "','" + cbogender.Text + "','" + txtage.Text + "','" + cbograde.Text + "','" + cbosection.Text + "','" + txtstudentid.Text + "');";
MySqlConnection connect = new MySqlConnection(con);
MySqlCommand cmd = new MySqlCommand(query, connect);
MySqlDataReader read;
try
{
connect.Open();
read = cmd.ExecuteReader();
MessageBox.Show("Succesful");
this.Hide();
while (read.Read())
{

}



}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else { MessageBox.Show("blee"); }



DISPLAY TO DATAGRADEVIEW




dgvstudent.Show();
dgvstudent.Visible = true;
dgvstudent.Location = new Point(177, 258);

try
{
string con = "datasource=localhost;port=3306;username=root;password=admin";
string query = "INSERT INTO stamonica.student(Name,Lastname,MI,Gender,Age,Grade,Section,StudentID) VALUES('" + txtname.Text + "','" + txtlast.Text + "','" + txtmi.Text + "','" + cbogender.Text + "','" + txtage.Text + "','" + cbograde.Text + "','" + cbosection.Text + "','" + txtstudentid.Text + "');";
MySqlConnection connect = new MySqlConnection(con);
MySqlDataAdapter mda = new MySqlDataAdapter("SELECT * FROM stamonica.student", connect);
MySqlCommand cmd = new MySqlCommand(query, connect);
connect.Open();
DataSet ds = new DataSet();
mda.Fill(ds, "stamonica");
dgvstudent.DataSource = ds.Tables["stamonica"];
connect.Close();


}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}




SEARCH USING TEXTBOX


MySqlConnection mcon = new MySqlConnection("datasource=localhost; port=3306; username=root; password=admin");
MySqlCommand cmd = new MySqlCommand("SELECT * FROM stamonica.student WHERE Lastname LIKE '%" + txtsearch.Text + "%'", mcon);
try
{
MySqlDataAdapter adap = new MySqlDataAdapter();
adap.SelectCommand = cmd;
DataTable dt = new DataTable();
adap.Fill(dt);
BindingSource bsource = new BindingSource();
bsource.DataSource = dt;
dgvstudent.DataSource = dt;
adap.Update(dt);
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{ MessageBox.Show(ex.Message); }

DISPLAY TO PANEL

label34.Text=dgvstudent.CurrentRow .Cells[1].Value.ToString();
label35.Text=dgvstudent.CurrentRow .Cells[2].Value.ToString();
label36.Text=dgvstudent.CurrentRow .Cells[3].Value.ToString();
label37.Text=dgvstudent.CurrentRow .Cells[4].Value.ToString();
label38.Text=dgvstudent.CurrentRow .Cells[5].Value.ToString();
label39.Text=dgvstudent.CurrentRow .Cells[6].Value.ToString();
label40.Text=dgvstudent.CurrentRow .Cells[7].Value.ToString();
label41.Text=dgvstudent.CurrentRow .Cells[8].Value.ToString();



PASSWORD USING ASTERESS

textBox2.UseSystemPasswordChar = true;



TABPAGES CODE

Graphics g = e.Graphics;
Brush _textBrush;



if (e.State == DrawItemState.Selected)
{

// Draw a different background color, and don't paint a focus rectangle.
_textBrush = new SolidBrush(Color.White);
g.FillRectangle(Brushes.Cyan, e.Bounds);
}
else
{
_textBrush = new System.Drawing.SolidBrush(e.ForeColor);
e.DrawBackground();
}

// Use our own font.
Font _tabFont = new Font("Tahoma", (float)10.0, FontStyle.Bold, GraphicsUnit.Pixel);

// Draw string. Center the text.
StringFormat _stringFlags = new StringFormat();
_stringFlags.Alignment = StringAlignment.Center;
_stringFlags.LineAlignment = StringAlignment.Center;



TIMER


label44.Text = DateTime.Now.ToLongDateString();
label45.Text = DateTime.Now.ToLongTimeString();
timer1.Start();


TEXRBOX SEARCH

Dataview DV=new Dataview(dbdataset);
DV.RowFilter=string.Format("Name LIKE ' %{0}%' ",Textbox.text);
Datagriedview.datasource=DV;



BUTTON UPDATE

UPDATE st = new UPDATE();
st.txtnam.Text = dgvstudent.CurrentRow.Cells[1].Value.ToString();
st.Show();


BUTTON SAVE


DialogResult dl = MessageBox.Show("Do you want to update this record?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
switch (dl)
{
case DialogResult.Yes:
// MySqlCommand cmd = new MySqlCommand("UPDATE table_Name set Name='" + txtnam.Text + "' WHERE dgvstudent.currentRow.Cell[0]Value.ToString()");
MessageBox.Show("Record has been updated");
break;

case DialogResult.No:
break;



HOW TO HUNG TO ADD

dataGridView1.Rows.Add(textBox1.Text, dataGridView1.Columns["name"] + textBox2.Text, dataGridView1.Columns["last"]);



Gamit ko po Visual Basic 2010 , Mysql Querybrowser and XAMPP.
Pag aralan niyo na lang po :)
 
Status
Not open for further replies.

About this Thread

  • 23
    Replies
  • 2K
    Views
  • 24
    Participants
Last reply from:
AimHigh_21

Trending Topics

Online now

Members online
1,093
Guests online
993
Total visitors
2,086

Forum statistics

Threads
2,274,853
Posts
28,958,844
Members
1,233,461
Latest member
Kdgwapo
Back
Top