下载 Npgsql.dll,Mono.Security.dll (基于.net framework 4.5 的postgresql 的连接工具)
导入到项目中。
private NpgsqlConnection conn;
string path = "Server=192.168.1.29;Port=5432;User Id=postgres;Password=root;Database=ohkuma;";
private void getWorkInstruction(object sender, EventArgs e)
{
try
{
conn = new NpgsqlConnection(path);
conn.Open();
// MessageBox.Show("连接成功");
string[] strs = QRCode.Text.Split(',');
NpgsqlParameter orderNoParam = new NpgsqlParameter("orderNo", DbType.String, 50);
NpgsqlParameter workInstructionIdParam = new NpgsqlParameter("workInstructionId", DbType.String, 50);
NpgsqlParameter produceDateParam = new NpgsqlParameter("produceDate", DbType.String, 50);
orderNoParam.Value = strs[0];
workInstructionIdParam.Value = strs[1];
produceDateParam.Value = strs[2];
string sql = string.Format(@" select * from fujiascom.e10201_work_instruction");
NpgsqlCommand command = new NpgsqlCommand(sql, conn);
NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter();
DataTable dt = new DataTable();
dataAdapter.SelectCommand = command;
int count = dataAdapter.Fill(dt);
}
catch (Exception ex)
{
}
}