本文整理汇总了C#中System.Data.SqlClient.SqlConnection.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.SqlClient.SqlConnection.Execute方法的具体用法?C# System.Data.SqlClient.SqlConnection.Execute怎么用?C# System.Data.SqlClient.SqlConnection.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlConnection
的用法示例。
在下文中一共展示了System.Data.SqlClient.SqlConnection.Execute方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public string Create(MaterialModel materialEntity)
{
try
{
using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
{
sqlConnection.Open();
string sqlQuery = "INSERT INTO Material(_MaterialType_key,MaterialID,MaterialName,_Workgroup_key,CreatedBy,DateCreated,ModifiedBy,DateModified) VALUES (@_MaterialType_key,@MaterialID,@MaterialName,@_Workgroup_key,@CreatedBy,@DateCreated,@ModifiedBy,@DateModified)";
sqlConnection.Execute(sqlQuery,
new
{
materialEntity._MaterialType_key,
materialEntity.MaterialID,
materialEntity.MaterialName,
materialEntity._Workgroup_key,
materialEntity.CreatedBy,
materialEntity.DateCreated,
materialEntity.ModifiedBy,
materialEntity.DateModified
});
sqlConnection.Close();
}
return "Created";
}
catch (Exception ex)
{
return ex.Message;
}
}
示例2: Create
public string Create(EventModel eventEntity)
{
try
{
using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
{
sqlConnection.Open();
string sqlQuery = "INSERT INTO Event(_EventType_key,EventID,EventName,ProjectedDate,ActualDate,_Workgroup_key,CreatedBy,DateCreated,ModifiedBy,DateModified) VALUES (@_EventType_key,@EventID,@EventName,@ProjectedDate,@ActualDate,@_Workgroup_key,@CreatedBy,@DateCreated,@ModifiedBy,@DateModified)";
sqlConnection.Execute(sqlQuery,
new
{
eventEntity._EventType_key,
eventEntity.EventID,
eventEntity.EventName,
eventEntity.ProjectedDate,
eventEntity.ActualDate,
eventEntity._Workgroup_key,
eventEntity.CreatedBy,
eventEntity.DateCreated,
eventEntity.ModifiedBy,
eventEntity.DateModified
});
sqlConnection.Close();
}
return "Created";
}
catch (Exception ex)
{
return ex.Message;
}
}
示例3: Create
public string Create(Customer customerEntity)
{
try
{
using(System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
{
sqlConnection.Open();
string sqlQuery =
"INSERT INTO [dbo].[Customer]([FirstName],[LastName],[Address],[City]) VALUES (@FirstName, @LastName, @Address, @City)";
sqlConnection.Execute(sqlQuery,
new
{
customerEntity.FirstName,
customerEntity.LastName,
customerEntity.Address,
customerEntity.City,
});
sqlConnection.Close();
}
return "Created";
}
catch (Exception ex)
{
return ex.Message;
}
}
示例4: Delete
/// <summary>
/// 删除权限
/// </summary>
public bool Delete(int id)
{
DynamicParameters p = new DynamicParameters();
p.Add("@PermissionID", id, DbType.Int32);
using (var conn = new System.Data.SqlClient.SqlConnection(ConnString))
{
return conn.Execute("sp_Accounts_DeletePermission", p, null, null, CommandType.StoredProcedure) == 1;
}
}
示例5: Update
/// <summary>
/// 更新权限信息
/// </summary>
public bool Update(int PermissionID, string description)
{
DynamicParameters p = new DynamicParameters();
p.Add("@PermissionID", PermissionID, DbType.Int32);
p.Add("@Description", description, DbType.String);
using (var conn = new System.Data.SqlClient.SqlConnection(ConnString))
{
return conn.Execute("sp_Accounts_UpdatePermission", p, null, null, CommandType.StoredProcedure)==1;
}
}
示例6: AddPermission
/// <summary>
/// 为角色增加权限
/// </summary>
public void AddPermission(int roleId, int permissionId)
{
DynamicParameters p = new DynamicParameters();
p.Add("@RoleID", roleId, DbType.Int32);
p.Add("@PermissionID", permissionId, DbType.Int32);
using (var conn = new System.Data.SqlClient.SqlConnection(ConnString))
{
conn.Execute("sp_Accounts_AddPermissionToRole", p, null, null, CommandType.StoredProcedure);
}
}
示例7: Delete
public bool Delete(int animalKey)
{
try
{
using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
{
sqlConnection.Open();
string sqlQuery = string.Format("DELETE FROM Material WHERE _Material_key={0}", animalKey);
sqlConnection.Execute(sqlQuery);
sqlConnection.Close();
}
return true;
}
catch (Exception exception)
{
return false;
}
}
示例8: Delete
public bool Delete(int customerId)
{
try
{
using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
{
sqlConnection.Open();
string sqlQuery = "DELETE FROM [dbo].[Customer] WHERE [email protected]";
sqlConnection.Execute(sqlQuery, new { customerId });
sqlConnection.Close();
}
return true;
}
catch (Exception exception)
{
return false;
}
}
示例9: UpdateGame
public void UpdateGame(game myGame)
{
using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
{
sqlConnection.Open();
sqlConnection.Execute(@"update game set
A1 = @A1, A2 = @A2, A3 = @A3,
B1 = @B1, B2 = @B2, B3 = @B3,
C1 = @C1, C2 = @C2, C3 = @C3,
status = @status, winner = @winner
where game_id = @gameid",
new
{
A1= myGame.A1,
A2 = myGame.A2,
A3 = myGame.A3,
B1 = myGame.B1,
B2 = myGame.B2,
B3 = myGame.B3,
C1 = myGame.C1,
C2 = myGame.C2,
C3 = myGame.C3,
status= myGame.status,
winner = myGame.winner,
gameid = myGame.game_id
});
sqlConnection.Close();
}
}
示例10: ProcessResponse
public static void ProcessResponse(List<Response> locationsResponse)
{
bool writeToFiles = Convert.ToBoolean(ConfigurationManager.AppSettings["writeToFiles"]);
StringBuilder sb = new StringBuilder();
sb.AppendLine(Headers);
for (int i = 0; i < locationsResponse.Count; i++)
{
if (writeToFiles)
{
sb.AppendFormat(HeaderFormat, "\"" + locationsResponse[i].postal_code.ToString() + "\"", "\"" + locationsResponse[i].timestamp.ToString().Replace("T00:00:00-05:00", "") + "\"",
locationsResponse[i].tempMin.ToString(), locationsResponse[i].tempAvg.ToString(), locationsResponse[i].tempMax.ToString(),
locationsResponse[i].cldCvrAvg.ToString(), locationsResponse[i].snowfall.ToString(), locationsResponse[i].precip.ToString());
sb.AppendLine();
string FileName = Folder + "\\" + PostalCode + "_" + CurrentTimeWindow.Replace("T00:00:00+00:00", "").Replace(".", "_").Replace(",", "_") + "_" + DateTime.Now.ToShortDateString().Replace("/", "") + ".csv";
System.IO.File.WriteAllText(FileName, sb.ToString());
}
else
{
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]))
{
con.Open();
string insert = "INSERT INTO WeatherResults ([timestamp],[postal_code],[tempMin],[tempAvg],[tempMax],[cldCvrAvg],[snowfall],[precip],[LastUpdated]) VALUES(@timestamp,@postal_code,@tempMin,@tempAvg,@tempMax,@cldCvrAvg,@snowfall,@precip,@LastUpdated)";
con.Execute(insert, new { timestamp = locationsResponse[i].timestamp.ToString().Replace("T00:00:00-05:00", ""), postal_code = locationsResponse[i].postal_code, tempMin = locationsResponse[i].tempMin, tempAvg = locationsResponse[i].tempAvg, tempMax = locationsResponse[i].tempMax,
cldCvrAvg = locationsResponse[i].cldCvrAvg, snowfall = locationsResponse[i].snowfall, precip = locationsResponse[i].precip, LastUpdated = DateTime.Now.ToShortDateString()});
//string update = "UPDATE us_postal_codes SET Done = 1 WHERE [Postal Code] = @postalcode";
//con.Execute(update, new { postalcode = locationsResponse[i].postal_code });
}
}
}
}
示例11: Update
public bool Update(Customer customerEntity)
{
try
{
using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
{
sqlConnection.Open();
string sqlQuery =
"UPDATE [dbo].[Customer] SET [FirstName] = @FirstName, [LastName] [email protected],[Address] [email protected],[City] = @City WHERE [email protected]";
sqlConnection.Execute(sqlQuery,
new
{
customerEntity.FirstName,
customerEntity.LastName,
customerEntity.Address,
customerEntity.City,
Id = customerEntity.CustomerId
});
sqlConnection.Close();
}
return true;
}
catch (Exception)
{
return false;
}
}
示例12: Update
public bool Update(MaterialModel animalEntity)
{
try
{
using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
{
sqlConnection.Open();
string sqlQuery = "UPDATE Material SET [email protected]_MaterialType_key,[email protected],[email protected] WHERE [email protected]_Material_key";
sqlConnection.Execute(sqlQuery, new
{
animalEntity._MaterialType_key,
animalEntity.MaterialID,
animalEntity.MaterialName,
animalEntity._Material_key
});
sqlConnection.Close();
}
return true;
}
catch (Exception exception)
{
return false;
}
}