작은 응용 프로그램을 만들고 있습니다. 이 응용 프로그램은 고객 정보 및 고객 사진을 저장합니다. 여기에 나는 datatable에서 datagridview로 데이터를 보여주고 싶을 때 문제가있다. 내 응용 프로그램은 이미지를 데이터베이스에 저장하지 않고 폴더에 저장합니다.DataTable에서 DataGridView (이미지 경로 포함)
그래서 내 데이터베이스에는 이미지 경로 만 저장됩니다. 하지만 전체 경로가 아니라 폴더 나 파일의 이름 만. 각 이름에 결합 된 경로를 사용합니다. 전체 경로를 유지하는 것과 비교하여 루트 디렉토리가 변경된 경우 폴더를 관리하는 것이 더 쉽습니다.
예를 들어 이미지 상자에 이미지를 표시하려면이 작업을 수행합니다. 후
//consider the record has been selected from table
classDirectory cd = new classDirectory();
// it will check current directory combine application name folder and branch name folder.
string branchFolderPath = cd.getBranchFolderPath(branchName);
string branchPanelPath = cd.getPanelFolderPath(branchFolderPath,panelName);
string customerPath = cd.getCustomerFolderPath(branchPanelPath,customerID + " - " + customerName);
string customerImage = path.Combine(customerPath,customerPicPath);
picCustomer.Image = new Bitmap(customerImage);
는 문자열 을 반환합니다, 결합 "C : \ 사용자는 내 이름 \ 문서 내 응용 프로그램 이름 \ 지점 이름 \ 패널 이름 \ 1235 \ \ - HIDAYAH \ 사진 \의 HIDAYAH - picture.jpg 대신"
을그래서 사진을 볼 수 있습니다.
그러나 그리드보기에서 데이터를 표시하는 방법을 모르겠습니다.
그래서 지금까지 방금 만들었습니다. cdb._listOfCustomer()
public DataTable _listOfCustomer()
{
cs.testConnection();
DataTable dtCustomer = new DataTable();
using (SqlConnection conn = new SqlConnection(cs.connString))
{
string query = "SELECT tbl_customer.customerPicPath as [Customer Image], tbl_customer.customerID as [Customer ID],tbl_customer.customerName as Name, tbl_branch.branchName as Branch, tbl_panel.panelName as Panel FROM (tbl_branch INNER JOIN tbl_panel ON tbl_branch.branchID = tbl_panel.branchID) INNER JOIN tbl_customer ON tbl_panel.panelID = tbl_customer.panelID;";
using (SqlDataAdapter adap = new SqlDataAdapter(query, conn))
{
adap.Fill(dtCustomer);
}
}
return dtCustomer;
어떤 제안에
는Customer.classDataBinding cdb = new Customer.classDataBinding();
DataTable dataCustomer = cdb._listOfCustomer();
dgvCustomer.DataSource = dataCustomer;
this.dgvCustomer.Columns["Customer Image"].Width = 120; //For a while, this code return the string only.
this.dgvCustomer.Columns["Customer ID"].Width = 120;
this.dgvCustomer.Columns["Name"].Width = 120;
this.dgvCustomer.Columns["Branch"].Width = 120;
this.dgvCustomer.Columns["Panel"].Width = 120;
코드? 누군가가 나를이 문제를 해결하는 데 도움이되기를 바랍니다. 고마워요!
체크 DataTable을 dataCustomer cdb._listOfCustomer =(); 행 집합을 검사하여 데이터가 실제로 데이터를 가지고 있는지 확인하십시오. 데이터가 있는지 알려주십시오. – KreepN