我是C#的新手,需要创建一个小表单应用程序,它有两个文本框,一个请求[File_ID],然后当按钮是按下将该号码发送到查询,并在另一个文本框中显示输出。C#按钮,将文本从一个文本框添加到另一个基于SQL查询的文本框
我一直在玩弄它,并有类似的东西。但它不起作用。我不确定我是否应该走另一个方向。我将衷心感谢您的帮助。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace testing
{
public partial class Form1 : Form
{
String str,dr;
SqlConnection con = new SqlConnection("Data Source=USHOU2016\\USFi;Initial Catalog=HOU_2016_Project;Integrated Security=True");
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
str = "SELECT TOP 1,[Sender Name],[Subject] from [OLE DB Destination] WHERE [CHAT #] ='" + textBox1.Text + "'";
cmd = new SqlCommand(str, con);
// dr = cmd.ExecuteReader();
con.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
textBox1.Text = cmd.ExecuteScalar().ToString();
}
}
}
谢谢。我将只需要C#作为一种工具,以表格格式输出我的SQL数据。我将如何执行cmd = new SqlCommand(str,con);我需要添加任何东西到文本框1? –