Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- using System.Data.SqlClient;
- namespace CapaAccesoDatos
- {
- public class DALCore
- {
- string CONNSTR;
- public DALCore()
- {
- CONNSTR = "Data Source=miservidor;"
- + "Initial Catalog=mibasedadatos;"
- + "Integrated Security=False;Pooling=False;"
- + "User ID=miusuario;"
- + "Password=mipassword;";
- }
- public void InsertarHIScore(string Nombre, int Score, out int? GetID)
- {
- try
- {
- using (SqlConnection conn = new SqlConnection(CONNSTR))
- using (SqlCommand cmd = conn.CreateCommand())
- {
- conn.Open();
- cmd.CommandText = "insert into test_HIScores (" +
- " Fecha" +
- ",UserName" +
- ",Score" +
- ") values (" +
- " @fecha" +
- ",@username" +
- ",@score" +
- ")";
- cmd.Parameters.Add("@fecha", SqlDbType.DateTime).Value = DateTime.Now;
- cmd.Parameters.Add("@username", SqlDbType.NVarChar, 50).Value = Nombre;
- cmd.Parameters.Add("@score", SqlDbType.Int).Value = Score;
- cmd.ExecuteNonQuery();
- cmd.Parameters.Clear();
- cmd.CommandText = "select IDENT_CURRENT('[dbo].[test_HIScores]')";
- var tmp = cmd.ExecuteScalar();
- if (tmp != null)
- {
- int p;
- bool b = int.TryParse(Convert.ToString(tmp), out p);
- if (b == true)
- GetID = p;
- else
- GetID = null;
- }
- else
- GetID = null;
- }
- }
- catch (Exception ex)
- {
- throw new System.Exception(ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement