PDA

View Full Version : مبتدی: مشکل در ثبت داده در دیتابیسی که detach شده



eligol
سه شنبه 29 شهریور 1390, 17:58 عصر
سلام
من 5 روزه وقت گزاشتم برای این کد ولی هنوز نتونستم داده ای را ثبت کنم
دیتابیس برنامه detach شده هست و من یک کانکشن با sql server database file درست کردم
حالا هر کاری می کنم نمی تونم در دیتابیسی که detach شده اطلاعاتی ثبت کنم از برنامه نویسان خواهش می کنم به من کمک کنن

sql server 2008,visual studio 2010
نام بانک gold نام جدول a1 نام فیلد جدول ma

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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
DataSet ds = new DataSet();
string strsql;
string strcon = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirecto ry|\\gold.mdf;Integrated Security=True;User Instance=True";
SqlDataAdapter da;
SqlConnection con;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'goldDataSet.a1' table. You can move, or remove it, as needed.
this.a1TableAdapter.Fill(this.goldDataSet.a1);
strsql = "select * from a1";
con = new SqlConnection(strcon);
con.Open();
da = new SqlDataAdapter(strsql, con);
da.Fill(ds, "a1");
textBox1.DataBindings.Add(new Binding("text", ds, "a1.ma"));
con.Close();

}

private void button1_Click(object sender, EventArgs e)
{
SqlCommand cmdclasf;
string strsql;
strsql = "insert into a1(" + "ma" + ") values('" + textBox1.Text + "')";
con.Open();
cmdclasf = new SqlCommand(strsql, con);
cmdclasf.ExecuteNonQuery();
con.Close();
MessageBox.Show("insert");
ds.Clear();
da.Fill(ds, "a1");
con.Close();

}
}
}