using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace Pharmacy
{
public partial class Form1 : Form
{
public DateTime dt = new DateTime(DateTime.Now.Ticks);
private DataSet data;
private SqlConnection connection;
public Form1()
{
InitializeComponent();
textBox1.Text = Convert.ToString(dt.ToLongDateString());
}
private void Form1_Load(object sender, EventArgs e)
{
string conStr = @"Data Source=.\SQLEXPRESS;
AttachDbFileNmae=|DataDirectory|Pharmacy.mdf;
Integrated Security=True;User Instance=True;";
connection = new SqlConnection(conStr);
data = new DataSet();
string sql = "SELECT ชื่อการค้า FROM Pharmacy";
SqlCommand command = new SqlCommand(sql,connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(data, "pha");
sql = "SELECT ขาย FROM Pharmacy";
command.CommandText = sql;
adapter.SelectCommand = command;
adapter.Fill(data, "phar");
connection.Close();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
string d;
for (int i = 0; i < data.Tables["pha"].Rows.Count; i++)
{
d = data.Tables["pha"].Rows[i][0].ToString();
listBox1.Items.Add(d);
}
}
แล้วพอผมรันโปรแกรมมันขึ้น error ว่า
Code
An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: Keyword not supported: 'attachdbfilenmae'.