我有班级报告和类程序,我想完成(迄今为止没有运气)是从类程序和方法SaveRep()发送数据到类Report方法Save()并保存它在这个方法。保存对象到数据库c#
我很抱歉,如果问题是严重制定,我真的坚持在这一点,请帮助。由于
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;
using System.Data.SqlClient;
namespace Application
{
class Program
{
static void Main(string[] args)
{
//call method SaveRep
}
public void SaveRep(...)
{
int RepID = 1;
string Data1 = "SomeData1"
string Data2 = "SomeData2"
//This method should send the data above to method Save() in Report class
//data to this method will be provided from another method.
}
}
public class Report
{
private static int _repID;
public int RepID
{
get { return _repID; }
set { _repID = value; }
}
private static string _data1;
public string Data1
{
get { return _data1; }
set { _data1 = value; }
}
private static string __data2;
public string Data1
{
get { return _data2; }
set { _data2 = value; }
}
public void Save()
{
string strConnectionString = (@"server=(local)\sqlexpress;Integrated Security=True;database=DataBase");
SqlConnection connection = new SqlConnection(strConnectionString);
connection.Open();
// This method should save all data (RepID,Data1,Data2)
// to the DB, provided to her by SaveRep method from Program class.
// Properties are columns from a database
}
}
}
恐怕这里没有问题。尝试取得一些进展,并回来更具体的问题。 –
我的问题是如何发送数据对象从SaveRep()保存()并将其保存到db.If有人有任何示例,将非常有帮助 – DareDevil