create table GuidTable
(
Id uniqueidentifier,
Name nvarchar(32)
)
select * from GuidTable
insert into GuidTable(Id,Name) values(NEWID(),N'嘿嘿')
//C#代码
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _03SqlHelperImprove
{
class Program
{
static void Main(string[] args)
{
#region MyRegion
//List<SqlParameter> listParameters =new List<SqlParameter>();
//listParameters.Add(new SqlParameter("@PageSize",2));
//listParameters.Add(new SqlParameter("@PageIndex",3));
//SqlParameter parameter =new SqlParameter("@TotalCount",SqlDbType.Int);
//parameter.Direction = ParameterDirection.Output;
//listParameters.Add(parameter);
//DataTable dt= SqlHelper.ExcuteDataTable("Pro_UserInfo_GetPageUserInfos", CommandType.StoredProcedure,
// listParameters.ToArray());
//foreach (DataRow dataRow in dt.Rows)
//{
// Console.WriteLine(dataRow[0]+" " +dataRow[1]);
//}
#endregion
#region 执行插入操作,然后返回插入的主键的ID
//string sql = "insert into DemoLastDAy(Name) output inserted.Id values('sss222222222') ";
//object result = SqlHelper.ExcuteScalar(sql);
//Console.WriteLine(result.ToString());
#endregion
#region 插入Guid类型的数据
string sql = "Insert into DemoGuid(Id,Name) values(@Id,@Name)";
SqlParameter[] parameters = new SqlParameter[2];
//Guid id =new Guid();//000000-000000-0000000-000
parameters[0]=new SqlParameter("@Id",Guid.NewGuid());
parameters[1] =new SqlParameter("@Name",DateTime.Now.ToString());
SqlHelper.ExcuteNonQuery(sql, parameters);
#endregion
Console.ReadKey();
}
}
}