|
|
|
ผมใช้ VC# 2008 กับ SQL SERVER 2008 ครับ เวลาที่ Insert ลง database ตอนรันบันทึกเรียบร้อยแต่พอมา รีเฟรช database มันก็กลับมาเหมือนเดิมคือมันไม่บันทึก |
|
|
|
|
|
|
|
เอา code มาดูหน่อย ครับ
|
|
|
|
|
Date :
2012-09-22 15:48:07 |
By :
chaokouy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หน้า Insert ครับ
Code (C#)
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.SqlClient;
namespace Project
{
public partial class Insertmain : Form
{
public Insertmain()
{
InitializeComponent();
}
private SqlConnection connection;
private SqlCommand command;
private string sql;
private void Insertmain_Load(object sender, EventArgs e)
{
string conStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DataPro.mdf;Integrated Security=True;User Instance=True;";
connection = new SqlConnection(conStr);
connection.Open();
sql = "SELECT type_id as max FROM workunit_type";
command = new SqlCommand(sql, connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet data = new DataSet();
adapter.Fill(data, "ty");
int numRow = data.Tables["ty"].Rows.Count;
numRow = numRow + 1;
string numRow2 = Convert.ToString(numRow);
numRow2 = "wt0" + numRow2;
textBox2.Text = numRow2;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
Workloadmain workmi = new Workloadmain();
workmi.Show();
connection.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
sql = "insert into workunit_type values(@user,@pass)";
//command = new SqlCommand(sql, connection);
command.CommandText = sql;
command.Parameters.AddWithValue("user", textBox2.Text);
command.Parameters.AddWithValue("pass", textBox1.Text);
int r = command.ExecuteNonQuery();
if (r > 0)
{
MessageBox.Show(textBox2.Text);
MessageBox.Show(textBox1.Text);
Close();
Workloadmain workmi = new Workloadmain();
workmi.Show();
connection.Close();
}
else
{
MessageBox.Show("เกิดความผิดพลาด กรุณาลองใหม่");
Close();
}
}
}
}
}
|
|
|
|
|
Date :
2012-09-22 15:51:05 |
By :
armlazy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณลองดูครับ ว่ามันได้เก็บ Database ไว้ที่ไหน
|
|
|
|
|
Date :
2012-09-23 06:08:03 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|