This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Data.SqlClient; | |
using System.Data.Sql; | |
using System.Linq; | |
using System.Text; | |
using System.Windows.Forms; | |
namespace killercodes_in.StrFromDb | |
{ | |
public partial class Form1 : Form | |
{ | |
private string _1_Con_Str = "Data Source=(local);Initial Catalog=napstrdb;User Id=sa;Password=iamadmin"; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private bool test_Connection() | |
{ | |
try | |
{ | |
SqlConnection _sqc = new SqlConnection(_1_Con_Str); | |
_sqc.Open(); | |
_sqc.Close(); | |
return true; | |
} | |
catch (Exception _Esq) | |
{ | |
label1.Text = _Esq.Message; | |
return false; | |
} | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
object g; | |
//g.GetType(); | |
if (test_Connection()) | |
{ | |
NewMethod(label1); | |
} | |
} | |
private void NewMethod(Label l) | |
{ | |
SqlCommand _scmd = new SqlCommand(); | |
_scmd.Connection = new SqlConnection(_1_Con_Str); | |
_scmd.Connection.Open(); | |
_scmd.CommandText = "Select * from string where msg='label'"; | |
SqlDataReader _sdr = _scmd.ExecuteReader(); | |
while (_sdr.Read()) | |
{ | |
l.Text = _sdr.GetValue(_sdr.GetOrdinal("info")).ToString(); | |
} | |
_sdr.Close(); | |
_scmd.Connection.Close(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
} | |
} | |
} |