-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmydatabase.cs
42 lines (38 loc) · 1.08 KB
/
mydatabase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace POS
{
class mydatabase
{
//Data source
private string strcon = @"Data Source=DESKTOP-31SFJVO;Initial Catalog=mypos;Integrated Security=True";
//SQL connection object
private SqlConnection Sqlcon;
public mydatabase()
{
Sqlcon = new SqlConnection(this.strcon);
}
public DataTable execyteSqlCommand(string sqlCommand)
{
DataTable dtTable = new DataTable();
try
{
//open sql connection
this.Sqlcon.Open();
// create sqlAdapter
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand, this.Sqlcon);
dataAdapter.Fill(dtTable);
this.Sqlcon.Close();
}
catch (Exception error)
{
Console.Write(error.ToString());
dtTable = null;
}
return dtTable;
}
}
}