私はC#を初めて使用しており、[File_ID]を要求する2つのテキストボックスを持つ小さなフォームアプリケーションを作成する必要があります。その番号をクエリに送信し、別のテキストボックスには出力を表示します。SQLクエリに基づいてテキストボックスのテキストを別のテキストボックスに追加するC#ボタン
私はこれで少し遊んでいて、このようなものを持っています。しかし、それは動作していません。私は別の方向に進むべきかどうか分からない。私は本当にあなたの助けに感謝します。
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();
}
}
}
ありがとうございます。私はちょうど私のSQLデータをフォーム形式で出力するためのツールとしてC#が必要になります。私はcmd = new SqlCommand(str、con)をどのように実行しますか?テキストボックス1に何かを追加する必要がありますか? –