YAY !!!!!!!! Fixed !!!!
This is how I did it :
DBC CLASS:
------------------------------------------------------------------
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 System.Data.SqlClient;
namespace Database2
{
class DBC
{
SqlConnection myConnection;
public DBC(string pass_word, string _account)
{
try
{
myConnection = new SqlConnection("user id=sa;"+"password="+pass_word+";"+"server=98.118.57.8;"+"database="+_account+";"+"connection timeout=30");
//"Trusted_Connection=yes;" +
}
catch //(Exception ex)
{
MessageBox.Show("");
}
}
public void connect()
{
myConnection.Open();
}
// TEST SELECT ... WORKS !!!! AHAHAHAH
public DataTable query()
{
DataTable table = new DataTable();
SqlDataAdapter dataAdapter = new SqlDataAdapter("select * from dbo.Pinfo", myConnection);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
dataAdapter.Fill(table);
return table;
}
// TEST UPDATE !! WORKS !!!! AHAHUAHUA
public DataTable query2()
{
DataTable table = new DataTable();
SqlDataAdapter dataAdapter = new SqlDataAdapter("UPDATE Pinfo SET Fname='Student'", myConnection);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
dataAdapter.Fill(table);
return table;
}
public void Close()
{
myConnection.Close();
}
internal string State()
{
return myConnection.State.ToString();
}
}
}
Form1
---------------------------------------------------------
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 System.Data.SqlClient;
namespace Database2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DBC db;
public void button1_Click(object sender, EventArgs e)
{
try
{
//_password();
db = new DBC(TB_password.Text, TB_database.Text);
db.connect();
LBL_status.Text = "Connected !!!!!!!!!";
DataTable table = db.query();
dataGridView1.DataSource = table;
}
catch (Exception ex)
{
LBL_status.Text = ex.Message;
}
}
private void button2_Click(object sender, EventArgs e)
{
DataTable table = db.query2();
dataGridView1.DataSource = table;
}
private void BTN_Q2_Click(object sender, EventArgs e)
{
DataTable table = db.query();
dataGridView1.DataSource = table;
}
public void _password()
{
// DBC obj = new DBC();
// obj.pass_word = TB_password.Text;
}
private void button1_Click_1(object sender, EventArgs e)
{
}
// public void _password()
// {
//DBC obj = new DBC(TB_password.Text);
//obj.pass_word = TB_password.Text;
//}
// private void button1_Click_1(object sender, EventArgs e)
// {
// LBL_status.Text = obj.pass_word;
// }
}
}
----SOLVED-----
I was able to make a string for the Password, and a string for the Account :D
Thanks you guys for all the replies...
I am aware that there are MANY MANY ways to get it done, and the code above probably isn't the best...
BUT HEY ! IT WORKED :D :D :D :D
I am very happy right now...
Once again, Thanks all ...