How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.
Do more with
private void button1_Click(object sender, EventArgs e)
{
DataRow data = DataByPass(passwordTb.Text);
if (data == null)
{
MessageBox.Show("Password Does Not Exist");
return;
}
int ID = Convert.ToInt32(data["ID"].ToString());
string NAME = data["NAME"].ToString();
string PASS = data["PASS"].ToString();
string SERVER = data["SERVER"].ToString();
string DATABASE = data["DATABASE"].ToString();
}
public static DataRow DataByPass(string pass)
{
var conStr = "My connection string";
using (var connection = new System.Data.SqlClient.SqlConnection(conStr))
{
connection.Open();
var cmd = new System.Data.SqlClient.SqlCommand("up_GetDataByPass", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Password", pass);
var dt = GetDataTable(cmd);
if (dt == null || dt.Rows.Count == 0)
{
//password does not exist
return null;
}
return dt.Rows[0];
}
}
public static DataTable GetDataTable(SqlCommand sql_command)
{
DataSet ds = null;
SqlDataAdapter adapter = null;
try
{
if (sql_command.Connection == null)
sql_command.Connection = DbConnection.SqlConnection;
ds = new DataSet("Temp");
adapter = new SqlDataAdapter(sql_command);
var rows = adapter.Fill(ds);
if (rows > 0)
{
return ds.Tables[0];
}
return null;
}
finally
{
if (adapter != null) adapter.Dispose();
if (ds != null) ds.Dispose();
}
}
create procedure up_GetDataByPass
@Password nvarchar(100) -- OR WHAT EVER THE PASSWORD DATA TYPE IS
AS
BEGIN
select * from TestTable where Pass = @Password
END
SqlConnection myConnection = new SqlConnection(@"Data Source=Rudu-Laptop\rudu;Initial Catalog=Secure;Integrated Security=True;");
or
SqlConnection myConnection = new SqlConnection("Data Source=Rudu-Laptop\\rudu;Initial Catalog=Secure;Integrated Security=True;");
Premium Content
You need an Expert Office subscription to comment.Start Free Trial