using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection Conn = new SqlConnection("Server="+textBox1.Text+";Database="+textBox2.Text+";User Id="+textBox3.Text+";Password="+textBox4.Text+;);
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Conn.Open();
MessageBox.Show("เชื่อมต่อฐานข้อมูลเรียบร้อย");
button2.Enabled = true;
}
catch
{
MessageBox.Show("ไม่สามารถเชื่อมต่อฐานข้อมูลได้");
}
}
}
}
รบกวนพี่ๆด้วยครับ
Tag : Ms SQL Server 2008, C#, VS 2012 (.NET 4.x), Windows
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Conn As SqlConnection
Private Sub Form1_Load(sender As Object, e As EventArgs)
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
Try
Conn = New SqlConnection("Server=" + textBox1.Text + ";Database=" + textBox2.Text + ";User Id=" + textBox3.Text + ";Password=" + textBox4.Text + ";")
Conn.Open()
MessageBox.Show("เชื่อมต่อฐานข้อมูลเรียบร้อย")
button2.Enabled = True
Catch
MessageBox.Show("ไม่สามารถเชื่อมต่อฐานข้อมูลได้")
End Try
End Sub
End Class