本文整理汇总了C#中System.Data.SqlClient.SqlConnection.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# SqlConnection.Insert方法的具体用法?C# SqlConnection.Insert怎么用?C# SqlConnection.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlConnection
的用法示例。
在下文中一共展示了SqlConnection.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert
public int Insert(BuybackResultAbsSale poco)
{
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ABS-SQL"].ConnectionString))
{
return (int)connection.Insert(poco);
}
}
示例2: AddCustomer
public void AddCustomer(Customer customer)
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
connection.Insert(CustomerTableName, ToKeyValuePairs(customer));
}
}
示例3: AddCase
public void AddCase(Case @case)
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
connection.Insert(CaseTableName, ToKeyValuePairs(@case));
}
}
示例4: SetupDB
private static void SetupDB()
{
var dbrecreated = false;
using (var connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;Initial Catalog=Master;Integrated Security=True"))
{
connection.Open();
try
{
connection.Execute(@" DROP DATABASE SimplecrudDemoWebsite; ");
}
catch (Exception ex)
{
Debug.WriteLine("database drop failed - close and reopen VS and try again:" + ex.Message);
}
try
{
connection.Execute(@" CREATE DATABASE SimplecrudDemoWebsite; ");
dbrecreated = true;
}
catch (Exception ex)
{
Debug.WriteLine("database create failed - close and reopen VS and try again:" + ex.Message);
}
}
if (!dbrecreated) return;
using (var connection = Utilities.GetOpenConnection())
{
connection.Execute(@" create TABLE Car (Id int IDENTITY(1,1) not null Primary Key, Make nvarchar(100) not null, ModelName nvarchar(100) not null) ");
connection.Insert(new CarViewModel() { Make = "Honda", ModelName = "Civic" });
connection.Execute(@" create TABLE Users (UserId int IDENTITY(1,1) not null Primary Key, FirstName nvarchar(100) not null, LastName nvarchar(100) not null, intAge int not null) ");
connection.Insert(new UserViewModel() {Age = 42, FirstName = "Jim", LastName = "Smith"});
connection.Execute(@" CREATE TABLE GUIDTest (guid uniqueidentifier NOT NULL,name varchar(50) NOT NULL, CONSTRAINT PK_GUIDTest PRIMARY KEY CLUSTERED (guid ASC))");
connection.Insert<Guid>(new GUIDTestViewModel {name = "Example"});
int x = 1;
do
{
connection.Insert(new User { FirstName = "Jim ", LastName = "Smith " + x, Age = x });
x++;
} while (x < 101);
}
}
示例5: SaveRule
public void SaveRule(Rule rule)
{
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
connection.Insert(rule);
connection.Close();
}
}
示例6: AddActivityToActivity
public bool AddActivityToActivity(int parentActivityId, int activityId)
{
var activityActivity = new ActivityActivity() {ActivityId = activityId, ParentActivityId = parentActivityId};
using (var conn = new SqlConnection(ConnectionString))
{
conn.Insert(activityActivity);
}
return true;
}
示例7: AddActivityToRole
public bool AddActivityToRole(int roleId, int activityId)
{
var roleActivity = new RoleActivity() {ActivityId = activityId, RoleId = roleId};
using (var conn = new SqlConnection(ConnectionString))
{
conn.Insert(roleActivity);
}
return true;
}
示例8: AddRoleToRole
public bool AddRoleToRole(int parentRoleId, int roleId)
{
var roleRole = new RoleRole() {RoleId = roleId, ParentRoleId = parentRoleId};
using (var conn = new SqlConnection(ConnectionString))
{
conn.Insert(roleRole);
}
return true;
}
示例9: AddRoleToUser
public bool AddRoleToUser(int userId, int roleId)
{
var userRole = new UserRole() {Id = userId, RoleId = roleId};
using (var conn = new SqlConnection(ConnectionString))
{
conn.Insert(userRole);
}
return true;
}
示例10: LogError
public void LogError(Error errorToLog)
{
Error result = null;
//save info to DB
using(SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["CrestDB"].ConnectionString))
{
result = connection.Insert<Error>(errorToLog);
}
Clients.All.broadcastMessage(result);
}
示例11: AddBookmarkRecord
public void AddBookmarkRecord(string bookmarkName, object workflowInstanceId)
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
connection.Insert(CaseWorkflowManager.BookmarkTableName,
new Dictionary<string, object>
{
{CaseWorkflowManager.CaseIdColumnName, _caseId},
{CaseWorkflowManager.WorkflowinstanceidColumnName, workflowInstanceId},
{CaseWorkflowManager.BookmarkNameColumnName, bookmarkName}
});
}
}
示例12: AddMessage
public void AddMessage(CaseMessage doc)
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
var dictionary = new Dictionary<string, object>
{
{"案件编号", doc.案件编号},
{"Content", doc.Content},
{"SenderName", doc.SenderUsername}
};
connection.Insert(TableName, dictionary);
}
}
示例13: Dapper
private static void Dapper(int eachCount)
{
GC.Collect();//回收资源
System.Threading.Thread.Sleep(2000);//休息2秒
//正试比拼
PerHelper.Execute(eachCount, "Dapper", () =>
{
using (SqlConnection conn = new SqlConnection(PubConst.connectionString))
{
var list = conn.Insert(GetList);
}
});
}
示例14: AddDoc
public void AddDoc(CaseDoc doc)
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
var dictionary = new Dictionary<string, object>
{
{"文件名", doc.FileName},
{"创建人", doc.UploadUserName},
{"创建日期", doc.UploadDateTime},
{"文件路径", doc.FilePath},
{"案件编号", doc.案件编号}
};
connection.Insert(CaseDocTableName, dictionary);
}
}
示例15: Insert
public static void Insert()
{
var contact = new Contact
{
FirstName = "New",
LastName = "Contact",
Email = "[email protected]"
};
using (var cn = new SqlConnection(CONNECTION_STRING))
{
var id = cn.Insert(contact);
Console.WriteLine("Inserted record ID: {0}", id);
}
Console.ReadKey();
}