Hi,
I am running my project in VS2008 and give datas to insert to table.
In current program, datas are added and when the program selects from that table, I see changes.
When rerunning the program after changing a little unrelated codes or close VS2008 and Open a new and run program again, that data does not appear to be added (but when I add data in server explorer of VS2008, without running the program, the data is added).
in class #1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Mallmanagement
{
public class mydataaccess
{
public string ServerName;
public string DBName = "goldDB.mdf";
public string username;
public string password;
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
public mydataaccess()
{
con = new SqlConnection();
cmd = new SqlCommand();
da = new SqlDataAdapter();
cmd.Connection = con;
da.SelectCommand = cmd;
}
public void connect()
{
string cs = "Data source=.\\SQLEXPRESS;Attachdbfilename=|DataDirectory|\\{0};Integrated security=true;user Instance=true";
cs = string.Format(cs, this.DBName);
con.ConnectionString = cs;
con.Open();
}
public void Disconnect()
{
con.Close();
}
public DataTable select(string sql)
{
DataTable dt = new DataTable();
cmd.CommandText = sql;
da.Fill(dt);
return dt;
}
public void docommand(string sql)
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
}
}
and class #2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Mallmanagement
{
class sanadlogic
{
mydataaccess md = new mydataaccess();
public int codehesab;
public int codesanad;
public int day;
public int month;
public int year;
public DataTable select()
{
md.connect();
string ss = "Select * from sanadha";
DataTable dt = new DataTable();
dt = md.select(ss);
md.Disconnect();
return dt;
}
public void Insert()
{
md.connect();
string AA = "Insert into sanadha(codesanad,codehesab,day,month,year)values({0},{1},{2},{3},{4}";
AA = string.Format(AA, this.codesanad, this.codehesab, this.day, this.month, this.year);
md.docommand(AA);
md.Disconnect();
}
}
}
What is the problem?
Can I to change, add, delete data in running program?
And can I change, add, delete data in tables?