두 개의 폼과 클래스가 있는데 쿼리는 저장 프로 시저에서 반환됩니다. 난 그냥 페치 형태 2와 콤보 상자에 채워 참조 단지 채워지지 않은 특정 값을 얻을 응용 프로그램을 실행할 때콤보 상자의 데이터 바인딩
-- Stored Procedure:
ALTER PROCEDURE [dbo].[Payment_Join]
@reference nvarchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT p.iPaymentID
, p.nvReference
, pt.nvPaymentType
, p.iAmount
, m.nvMethod
, u.nvUsers
, p.tUpdateTime
FROM Payment p
, tblPaymentType pt
, tblPaymentMethod m
, tblUsers u
WHERE p.nvReference = @reference
and p.iPaymentTypeID = pt.iPaymentTypeID
and p.iMethodID = m.iMethodID
and p.iUsersID = u.iUsersID
END
// payment.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace Finance {
class payment {
string connection = global::Finance.Properties.Settings.Default.PaymentConnectionString;
#region Fields
int _paymentid = 0;
string _reference = string.Empty;
string _paymenttype;
double _amount = 0;
string _paymentmethod;
string _employeename;
DateTime _updatetime = DateTime.Now;
#endregion
#region Properties
public int paymentid
{
get { return _paymentid; }
set { _paymentid = value; }
}
public string reference
{
get { return _reference; }
set { _reference = value; }
}
public string paymenttype
{
get { return _paymenttype; }
set { _paymenttype = value; }
}
public string paymentmethod
{
get { return _paymentmethod; }
set { _paymentmethod = value; }
}
public double amount
{
get { return _amount;}
set { _amount = value; }
}
public string employeename
{
get { return _employeename; }
set { _employeename = value; }
}
public DateTime updatetime
{
get { return _updatetime; }
set { _updatetime = value; }
}
#endregion
#region Constructor
public payment()
{
}
public payment(string refer)
{
reference = refer;
}
public payment(int paymentID, string Reference, string Paymenttype, double Amount, string Paymentmethod, string Employeename, DateTime Time)
{
paymentid = paymentID;
reference = Reference;
paymenttype = Paymenttype;
amount = Amount;
paymentmethod = Paymentmethod;
employeename = Employeename;
updatetime = Time;
}
#endregion
#region Methods
public void Save()
{
try
{
SqlConnection connect = new SqlConnection(connection);
SqlCommand command = new SqlCommand("payment_create", connect);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@reference", reference));
command.Parameters.Add(new SqlParameter("@paymenttype", paymenttype));
command.Parameters.Add(new SqlParameter("@amount", amount));
command.Parameters.Add(new SqlParameter("@paymentmethod", paymentmethod));
command.Parameters.Add(new SqlParameter("@employeename", employeename));
command.Parameters.Add(new SqlParameter("@updatetime", updatetime));
connect.Open();
command.ExecuteScalar();
connect.Close();
}
catch
{
}
}
public void Load(string reference)
{
try
{
SqlConnection connect = new SqlConnection(connection);
SqlCommand command = new SqlCommand("Payment_Join", connect);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@Reference", reference));
//MessageBox.Show("ref = " + reference);
connect.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
this.reference = Convert.ToString(reader["nvReference"]);
// MessageBox.Show(reference);
// MessageBox.Show("here");
// MessageBox.Show("payment type id = " + reader["nvPaymentType"]);
// MessageBox.Show("here1");
this.paymenttype = Convert.ToString(reader["nvPaymentType"]);
// MessageBox.Show(paymenttype.ToString());
this.amount = Convert.ToDouble(reader["iAmount"]);
this.paymentmethod = Convert.ToString(reader["nvMethod"]);
this.employeename = Convert.ToString(reader["nvUsers"]);
this.updatetime = Convert.ToDateTime(reader["tUpdateTime"]);
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show("Check it again" + ex);
}
}
#endregion
}
}
이미 디자이너, 를 통해 콤보 상자 항목을 바인더 제본했다. C#에 익숙해 져서 익숙해 지도록 도와주세요
웹이나 윈폼 : 여기
은 예입니다? –질문을 더 명확하게 나타낼 수 있습니까? 나는 당신이 무엇을 요구하고 있는지 이해하는데 어려움을 겪고있다. 이것은 Windows 양식입니까 아니면 웹 응용 프로그램입니까? –