我有班級報告和類程序,我想完成(迄今爲止沒有運氣)是從類程序和方法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