如何从SQL DB中获取数据,其中emp_code位于datagridview中 [英] How to get data from SQL DB where emp_code in datagridview
问题描述
亲爱的,你好吗?
现在我从excel表导入数据这个数据包括员工代码,我需要的是获得employee_payment和working_days来自数据网格视图中的emp_master表foreach emp_code然后将它们添加到数据网格视图中的两个新列中
这是我当前的代码
Dear All,How are you?
now iam importing data from excel sheet this data include employee code, the thing that i need is to get employee_payment and working_days from emp_master table foreach emp_code in datagridview then add them in two new Columns in the data grid view
this is my current code
import_grid.Columns.Add("not_hours_amount", "not_hours_amount");
import_grid.Columns.Add("hot_hours_amount", "hot_hours_amount");
string emp_code = string.Empty;
foreach (DataGridViewRow row in import_grid.Rows)
{
emp_code = row.Cells[1].Value.ToString();
SqlConnection cn =
new SqlConnection(ConfigurationManager.ConnectionStrings["payroll"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT * FROM [employee_master] WHERE emp_code='" + emp_code + "'", cn);
cmd.CommandType = CommandType.Text;
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
//More code here
}
这是我的GUI
http://i.imgur.com/qVofbMb.jpg [ ^ ]
我尝试过:
import_grid.Columns.Add(not_hours_amount,not_hours_amount);
import_grid.Columns.Add(hot_hours_amount,hot_hours_amount);
string emp_code = string.Empty;
foreach(import_grid.Rows中的DataGridViewRow行)
{
emp_code = row.Cells [1] .Value.ToString();
SqlConnection cn =
new SqlConnection(ConfigurationManager.ConnectionStrings [payroll ] .ConnectionString);
SqlCommand cmd = new SqlCommand(SELECT * FROM [employee_master] WHERE emp_code ='+ emp_code +',cn);
cmd.CommandType = CommandType.Text;
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
//这里有更多代码
}
this is my GUI
http://i.imgur.com/qVofbMb.jpg[^]
What I have tried:
import_grid.Columns.Add("not_hours_amount", "not_hours_amount");
import_grid.Columns.Add("hot_hours_amount", "hot_hours_amount");
string emp_code = string.Empty;
foreach (DataGridViewRow row in import_grid.Rows)
{
emp_code = row.Cells[1].Value.ToString();
SqlConnection cn =
new SqlConnection(ConfigurationManager.ConnectionStrings["payroll"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT * FROM [employee_master] WHERE emp_code='" + emp_code + "'", cn);
cmd.CommandType = CommandType.Text;
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
//More code here
}
推荐答案
对此问题的任何帮助
这篇关于如何从SQL DB中获取数据,其中emp_code位于datagridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!