이전에 만든 양식의 TextBox에 입력 한 정보를 레지스트리에 저장했습니다. 양식을 연 후 양식에 저장된 모든 정보를 표시하려고합니다. TextBox. 다음 코드를 실행하려고하면 null 값이 반환됩니다. 무엇이 문제일까요?TextBox (C#)에서 값 가져 오기
는코드 :
SQLSERVER = textBox1.Text;
SQLDATABASE = textBox2.Text;
SQLUSER = textBox3.Text;
SQLPASS = textBox4.Text;
try
{
SqlConnection Baglanti = new SqlConnection("Data Source='" + SQLSERVER + "'; Initial Catalog='" + SQLDATABASE + "'; User id='" + SQLUSER + "'; Password='" + SQLPASS + "';");
Baglanti.Open();
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software", true);
if (key != null)
{
RegistryKey key2 = key.CreateSubKey("BilkerSoft");
key.SetValue("SQLSERVER", SQLSERVER, RegistryValueKind.String);
Registry.CurrentUser.CreateSubKey("BilkerSoft").SetValue("SQLSERVER", SQLSERVER);
Registry.CurrentUser.CreateSubKey("BilkerSoft").SetValue("DATABASE", SQLDATABASE);
Registry.CurrentUser.CreateSubKey("BilkerSoft").SetValue("USER", SQLUSER);
Registry.CurrentUser.CreateSubKey("BilkerSoft").SetValue("PASSWORD", SQLPASS);
}
}
catch (Exception ex)
{
MessageBox.Show("Hata oluştu:'" + ex.Message + "'");
}
RegistryKey key1 = Registry.CurrentUser.OpenSubKey("BilkerSoft",true);
try
{
if (key1 != null)
{
key1.SetValue("SQLSERVER", SQLSERVER, RegistryValueKind.String);
Registry.CurrentUser.OpenSubKey("BilkerSoft").GetValue("SQLSERVER", SQLSERVER);
Registry.CurrentUser.OpenSubKey("BilkerSoft").GetValue("DATABASE", SQLDATABASE);
Registry.CurrentUser.OpenSubKey("BilkerSoft").GetValue("USER", SQLUSER);
Registry.CurrentUser.OpenSubKey("BilkerSoft").GetValue("PASSWORD", SQLPASS);
}
Baglanti = new SqlConnection("Data Source='" + SQLSERVER + "';Initial Catalog='" + SQLDATABASE + "';User id='" + SQLUSER + "';Password='" + SQLPASS + "'");
Baglanti.Open();
Baglanti.Close();
MessageBox.Show("Kayıt Başarılı");
}
catch (Exception ex)
{
MessageBox.Show("Hata oluştu:'" + ex.Message + "'");
}
}
private void Form1_Load(object sender, EventArgs e)
{
RegistryKey key2 = Registry.CurrentUser.OpenSubKey("BilkerSoft", true);
textBox1.Text = Registry.CurrentUser.OpenSubKey("BilkerSoft").GetValue("SQLSERVER", SQLSERVER).ToString();
textBox2.Text = Registry.CurrentUser.OpenSubKey("BilkerSoft").GetValue("DATABASE", SQLDATABASE).ToString();
textBox3.Text = Registry.CurrentUser.OpenSubKey("BilkerSoft").GetValue("USER", SQLUSER).ToString();
textBox4.Text = Registry.CurrentUser.OpenSubKey("BilkerSoft").GetValue("PASSWORD", SQLPASS).ToString();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
당신의 MEEN의 textBox1.Text == null이? –
null입니까? 키? key1? 모두들? – itsmatt
@ itsmatt-key1은 null입니다. – Selo