今C#を使用して、個別詳細検索機能の実装を行っております。
内容と致しましては、画面で、顧客IDを入力すると顧客の個別情報が
画面に表示される形です。
コーディングをしたのですが、SQL文でコンパイルエラーが出てしまい
困っておりまして、どうすれば、SQL文のエラーがなくなるかお教え頂けますでしょうか。
===================
以下詳細検索機能のソースです。
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace WebApplication1
{
public partial class Syosai : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\user\documents\visual studio 2010\Projects\WebApplication1\WebApplication1\App_Data\SyainDB.mdf;Integrated Security=True;User Instance=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
//システムの仕組みは、テキストの入力した個別IDが、SyaIDに入り
//個別の情報を検索し、表示する仕組みです。
//以下のSQL文でエラーが出てきております
//エラー内容は引用符が欠けているとのことです。
string SyaID = txtSyaID.Text;
string strSql = "SELECT * FROM Syain WHERE'" + "Sya_ID =" + SyaID ;
SqlCommand cmd = new SqlCommand(strSql, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read()) { TableRow tRow = new TableRow(); TableCell tCell1 = new TableCell(); TableCell tCell2 = new TableCell(); TableCell tCell3 = new TableCell(); TableCell tCell4 = new TableCell(); tCell1.Text = dr["Sya_ID"].ToString(); tRow.Cells.Add(tCell1); tCell2.Text = dr["Sya_Name"].ToString(); tRow.Cells.Add(tCell2); tCell3.Text = dr["Sya_Syozoku"].ToString(); tRow.Cells.Add(tCell3); tCell4.Text = dr["Sya_Mail"].ToString(); tRow.Cells.Add(tCell4); Table1.Rows.Add(tRow); } dr.Close(); con.Close(); } private void ExecNonQuery(string strSql) { con.Open(); SqlCommand cmd = new SqlCommand(strSql, con); try { int numResult = cmd.ExecuteNonQuery(); } catch (SqlException) { } con.Close(); Response.Redirect("Syosai.aspx"); } }
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/29 12:27
2015/12/29 12:46
2015/12/29 12:49
2015/12/29 12:59
2015/12/29 13:15