Visual Studio에서 C#을 사용하여 작업하고 있습니다. SQL Server의 다른 데이터베이스 테이블에서 Visual Studio 폼의 텍스트 상자로 데이터를 가져와야합니다. 데이터베이스 테이블에는 여러 행과 열이 있습니다. 값은 문자 및 실수 값입니다. 아래 코드를 사용하고 있습니다. 나는 텍스트 상자에 실제 가치를주지 않는다. 오류가없고 빈 텍스트 상자가 나타납니다. 나는 성격 가치를 얻을 수있다. 아무도 도와 줄 수 있습니까? 감사.SQL Server에서 Visual Studio의 텍스트 상자로 데이터를 가져 오는 방법
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SqlConnection con = new SqlConnection("DataSource=192.146.1,5,1433;Network Library=DBMSSOCN;Initial Catalog=Estimator;User ID=id;Password=password;Trusted_Connection=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from Table1", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
textBox1.Text = dr.GetString(1);
textBox2.Text = dr.GetString(2);
textBox2.Text = dr.GetString(3);
}
con.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
코드를 디버깅 할 때 while 루프를 입력합니까? –
예, while 루프에 들어갑니다. 감사합니다. –
www에 공개 IP 주소를 표시하지 마십시오. 질문을 수정하고 다른 것으로 변경하십시오. xxx.xxx.xxx.xxx처럼 – jonathana