1
내 코드는 다음과 같습니다.데이터 어댑터를 사용하여 데이터 세트 작성
SqlCommand command = new SqlCommand();
command.Parameters.AddWithValue("@AccountId", accountNumberLong);
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT * FROM T_POSTAGE_DISCOUNT");
sqlQuery = sql.ToString();
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = sqlQuery;
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
dataAdapter.Fill(dsDiscounts, "Discounts");
}
개까지 작동합니다. 이 데이터 세트에 다른 테이블을 추가하고 싶습니다. 그 때 나는 이것을 좋아했다.
command.Parameters.AddWithValue("@DISCOUNT_LEVEL_NBR",discountLevelNBR);
sql.AppendLine("select * from T_CONTRACT WHERE [email protected]_LEVEL_NBR");
sqlQuery = sql.ToString();
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = sqlQuery;
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
dataAdapter.Fill(dsDiscounts,"CONTRACT");
}
모든 테이블을 다시 추가합니다. 기존 datatset에 onlt 계약 테이블을 추가하고 싶습니다.
어떻게 할 수 있습니까? (C#)
내가 다시 쿼리를 추가 생각"sql.AppendLine ("DISCOUNT_LEVEL_NBR = @ DISCOUNT_LEVEL_NBR가 WHERE T_CONTRACT SELECT * FROM);"당신이 두 번째로 실행하면, 그래서 실행 두 ... –
사실 그것은 별도의 쿼리입니다. 두 개의 쿼리에서 테이블 이름이 다릅니다. 지금 어떻게해야합니까? –
새 문자열 작성기 작성 StringBuilder sql1 = new StringBuilder(); 그런 다음 sql1.AppendLine ("select * from T_CONTRACT WHERE DISCOUNT_LEVEL_NBR = @ DISCOUNT_LEVEL_NBR"); sqlQuery = sql1.ToString(); –