当前位置: 首页>>代码示例>>C#>>正文


C# SqlCommandBuilder.RefreshSchema方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlCommandBuilder.RefreshSchema方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommandBuilder.RefreshSchema方法的具体用法?C# SqlCommandBuilder.RefreshSchema怎么用?C# SqlCommandBuilder.RefreshSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlCommandBuilder的用法示例。


在下文中一共展示了SqlCommandBuilder.RefreshSchema方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LogonUser

 public static DataTable LogonUser(string userName,string password)
 {
     SqlConnection cn = null;
     try
     {
         cn = new SqlConnection(ConfigurationSettings.AppSettings["cn"]);
         cn.Open();
         userName = userName.Replace("'","''");
         password = password.Replace("'","''");
         SqlDataAdapter da = new SqlDataAdapter("SELECT KullaniciAdi, Sifre, KullaniciId, Adi_SoyAdi, Unvan, Email, Aciklama, DilId, CreDate, ModDate, IsOnay, IsAktif, ModUser, CreUser FROM tGuvKullanici where KullaniciAdi='"+ userName + "' and Sifre='"+ password + "'",cn);
         System.Data.DataSet ds = new DataSet();
         da.Fill(ds);
         SqlCommandBuilder builder = new SqlCommandBuilder(da);
         builder.RefreshSchema();
         return ds.Tables[0];
     }
     catch(Exception ex)
     {
         return new DataTable();
     }
     finally
     {
         if (cn!=null)
         {
             if (cn.State != ConnectionState.Closed)
                 cn.Close();
         }
     }
 }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:29,代码来源:GeneralMethods.cs

示例2: QuoteSuffix_DeleteCommand_Generated

		public void QuoteSuffix_DeleteCommand_Generated ()
		{
			SqlCommand cmd = null;

			try {
				string selectQuery = "select id, lname from employee where id = 3";
				SqlDataAdapter da = new SqlDataAdapter (selectQuery, conn);
				DataSet ds = new DataSet ();
				da.Fill (ds, "IntTest");

				SqlCommandBuilder cb = new SqlCommandBuilder (da);
				cmd = cb.GetDeleteCommand ();
				Assert.AreEqual ("]", cb.QuoteSuffix, "#1");
				try {
					cb.QuoteSuffix = "\"";
					Assert.Fail ("#2");
				} catch (InvalidOperationException ex) {
					// The QuotePrefix and QuoteSuffix properties
					// cannot be changed once an Insert, Update, or
					// Delete command has been generated
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
					Assert.IsNull (ex.InnerException, "#4");
					Assert.IsNotNull (ex.Message, "#5");
				}
				Assert.AreEqual ("]", cb.QuoteSuffix, "#6");
				cb.RefreshSchema ();
				cb.QuoteSuffix = "\"";
			} finally {
				if (cmd != null)
					cmd.Dispose ();
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:32,代码来源:SqlCommandBuilderTest.cs

示例3: GetInsertCommand1

		public void GetInsertCommand1 ()
		{
			SqlCommand cmd = null;

			try {
				string selectQuery = "select id, fname, lname " +
					"from employee where id = 1";
				SqlDataAdapter da = new SqlDataAdapter (selectQuery, conn);
				DataSet ds = new DataSet ();
				da.Fill (ds, "IntTest");
				Assert.AreEqual (1, ds.Tables.Count);

				SqlCommandBuilder cb;
				
				cb = new SqlCommandBuilder (da);
				cmd = cb.GetInsertCommand ();
				Assert.AreEqual ("INSERT INTO [employee] ([id], " +
					"[fname], [lname]) VALUES (@p1, @p2, @p3)",
					cmd.CommandText, "#A1");
				Assert.AreSame (conn, cmd.Connection, "#A2");
				AssertInsertParameters (cmd, false, "#A3:");
				Assert.AreSame (cmd, cb.GetInsertCommand (), "#A4");

				cb.RefreshSchema ();
				cb.QuotePrefix = "\"";
				cmd = cb.GetInsertCommand ();
				Assert.AreEqual ("INSERT INTO \"employee] (\"id], " +
					"\"fname], \"lname]) VALUES (@p1, @p2, @p3)",
					cmd.CommandText, "#B1");
				Assert.AreSame (conn, cmd.Connection, "#B2");
				AssertInsertParameters (cmd, false, "#B3:");
				Assert.AreSame (cmd, cb.GetInsertCommand (), "#B4");

				cb.RefreshSchema ();
				cb.QuoteSuffix = "\"";
				cmd = cb.GetInsertCommand ();
				Assert.AreEqual ("INSERT INTO \"employee\" (\"id\", "
					+ "\"fname\", \"lname\") VALUES (@p1, @p2, @p3)",
					cmd.CommandText, "#C1");
				Assert.AreSame (conn, cmd.Connection, "#C2");
				AssertInsertParameters (cmd, false, "#C3");
				Assert.AreSame (cmd, cb.GetInsertCommand (), "#C4");
			} finally {
				if (cmd != null)
					cmd.Dispose ();
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:47,代码来源:SqlCommandBuilderTest.cs

示例4: GetDeleteCommand

		[Test] // GetDeleteCommand ()
		public void GetDeleteCommand1 ()
		{
			SqlCommand cmd = null;

			try {
				string selectQuery = "select id, fname, lname, " +
					"id+2 as next_id from employee where " +
					"id = 3 and lname = 'A' and fname = 'B'";
				SqlDataAdapter da = new SqlDataAdapter (selectQuery, conn);
				DataSet ds = new DataSet ();
				da.Fill (ds, "IntTest");
				Assert.AreEqual (1, ds.Tables.Count);

				SqlCommandBuilder cb = new SqlCommandBuilder (da);
				cmd = cb.GetDeleteCommand ();
				Assert.AreEqual ("DELETE FROM [employee] WHERE " +
					"(([id] = @p1) AND ([fname] = @p2) AND " +
					"((@p3 = 1 AND [lname] IS NULL) OR " +
					"([lname] = @p4)))", cmd.CommandText, "#A1");
				Assert.AreSame (conn, cmd.Connection, "#A2");
				AssertDeleteParameters (cmd, false, "#A3:");
				Assert.AreSame (cmd, cb.GetDeleteCommand (), "#A4");

				cb.RefreshSchema ();
				cb.QuotePrefix = "\"";
				cmd = cb.GetDeleteCommand ();

				Assert.AreEqual ("DELETE FROM \"employee] WHERE " +
					"((\"id] = @p1) AND (\"fname] = @p2) AND " +
					"((@p3 = 1 AND \"lname] IS NULL) OR " +
					"(\"lname] = @p4)))", cmd.CommandText, "#B1");
				Assert.AreSame (conn, cmd.Connection, "#B2");
				AssertDeleteParameters (cmd, false, "#B3:");
				Assert.AreSame (cmd, cb.GetDeleteCommand (), "#B4");

				cb.RefreshSchema ();
				cb.QuoteSuffix = "\"";
				cmd = cb.GetDeleteCommand ();

				Assert.AreEqual ("DELETE FROM \"employee\" WHERE " +
					"((\"id\" = @p1) AND (\"fname\" = @p2) AND " +
					"((@p3 = 1 AND \"lname\" IS NULL) OR " +
					"(\"lname\" = @p4)))", cmd.CommandText, "#C1");
				Assert.AreSame (conn, cmd.Connection, "#C2");
				AssertDeleteParameters (cmd, false, "#C3:");
				Assert.AreSame (cmd, cb.GetDeleteCommand (), "#C4");
			} finally {
				if (cmd != null)
					cmd.Dispose ();
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:52,代码来源:SqlCommandBuilderTest.cs

示例5: GetUpdateCommand

		[Test] // GetUpdateCommand ()
		public void GetUpdateCommand1 ()
		{
			SqlCommand cmd = null;

			try {
				string selectQuery = "select id, fname, lname, " +
					"id+1 as next_id from employee where " +
					"id = 3 and lname = 'A' and fname = 'B'";
				SqlDataAdapter da = new SqlDataAdapter (selectQuery, conn);
				DataSet ds = new DataSet ();
				da.Fill (ds, "IntTest");
				Assert.AreEqual (1, ds.Tables.Count);

				SqlCommandBuilder cb = new SqlCommandBuilder (da);
				cmd = cb.GetUpdateCommand ();
#if NET_2_0
				Assert.AreEqual ("UPDATE [employee] SET [id] = @p1, " +
					"[fname] = @p2, [lname] = @p3 WHERE (([id] = @p4) " +
					"AND ([fname] = @p5) AND ((@p6 = 1 " +
					"AND [lname] IS NULL) OR ([lname] = @p7)))",
					cmd.CommandText, "#A1");
#else
				Assert.AreEqual ("UPDATE employee SET id = @p1 , " +
					"fname = @p2 , lname = @p3 WHERE ( (id = @p4) " +
					"AND ((@p5 = 1 AND fname IS NULL) OR " +
					"(fname = @p6)) AND ((@p7 = 1 AND " +
					"lname IS NULL) OR (lname = @p8)) )",
					cmd.CommandText, "#A1");
#endif
				Assert.AreSame (conn, cmd.Connection, "#A2");
				AssertUpdateParameters (cmd, false, "#A3:");
				Assert.AreSame (cmd, cb.GetUpdateCommand (), "#A4");

				cb.RefreshSchema ();
				cb.QuotePrefix = "\"";
				cmd = cb.GetUpdateCommand ();
#if NET_2_0
				Assert.AreEqual ("UPDATE \"employee] SET \"id] = @p1, " +
					"\"fname] = @p2, \"lname] = @p3 WHERE ((\"id] = @p4) " +
					"AND (\"fname] = @p5) AND ((@p6 = 1 " +
					"AND \"lname] IS NULL) OR (\"lname] = @p7)))",
					cmd.CommandText, "#B1");
#else
				Assert.AreEqual ("UPDATE \"employee SET \"id = @p1 , " +
					"\"fname = @p2 , \"lname = @p3 WHERE ( (\"id = @p4) " +
					"AND ((@p5 = 1 AND \"fname IS NULL) OR " +
					"(\"fname = @p6)) AND ((@p7 = 1 AND " +
					"\"lname IS NULL) OR (\"lname = @p8)) )",
					cmd.CommandText, "#B1");
#endif
				Assert.AreSame (conn, cmd.Connection, "#B2");
				AssertUpdateParameters (cmd, false, "#B3:");
				Assert.AreSame (cmd, cb.GetUpdateCommand (), "#B4");

				cb.RefreshSchema ();
#if NET_2_0
				cb.QuoteSuffix = "\"";
#else
				cb.QuoteSuffix = "´";
#endif
				cmd = cb.GetUpdateCommand ();
#if NET_2_0
				Assert.AreEqual ("UPDATE \"employee\" SET \"id\" = @p1, " +
					"\"fname\" = @p2, \"lname\" = @p3 WHERE ((\"id\" = @p4) " +
					"AND (\"fname\" = @p5) AND ((@p6 = 1 " +
					"AND \"lname\" IS NULL) OR (\"lname\" = @p7)))",
					cmd.CommandText, "#C1");
#else
				Assert.AreEqual ("UPDATE \"employee´ SET \"id´ = @p1 , " +
					"\"fname´ = @p2 , \"lname´ = @p3 WHERE ( (\"id´ = @p4) " +
					"AND ((@p5 = 1 AND \"fname´ IS NULL) OR " +
					"(\"fname´ = @p6)) AND ((@p7 = 1 AND " +
					"\"lname´ IS NULL) OR (\"lname´ = @p8)) )",
					cmd.CommandText, "#C1");
#endif
				Assert.AreSame (conn, cmd.Connection, "#C2");
				AssertUpdateParameters (cmd, false, "#C3:");
				Assert.AreSame (cmd, cb.GetUpdateCommand (), "#C4");
			} finally {
				if (cmd != null)
					cmd.Dispose ();
			}
		}
开发者ID:symform,项目名称:mono,代码行数:84,代码来源:SqlCommandBuilderTest.cs

示例6: cargaVistaVendedores

 /*Esta función es la encargada de en MODO DESCONECTADO, cargar los vendedores de la BD
  *y devolvernos un DataView que manipularemos a posteriori*/
 protected DataView cargaVistaVendedores()
 {
     SqlConnection conexion;
     DataSet dataSet;
     String sentencia;
     SqlDataAdapter dataAdapterVendedor;
     DataView dataViewVendedor = new DataView();
     SqlCommandBuilder comandBuilderVendedor;
     string cadenaConexion = System.Configuration.ConfigurationManager.ConnectionStrings["DB_FACTURACION"].ConnectionString;
     conexion = new SqlConnection(cadenaConexion);
     sentencia = "SELECT COD_VEN,Nombre,Telefono FROM TB_Vendedor";
     dataAdapterVendedor = new System.Data.SqlClient.SqlDataAdapter(sentencia, conexion);
     dataAdapterVendedor.TableMappings.Add("Table", "Vendedor");
     comandBuilderVendedor = new System.Data.SqlClient.SqlCommandBuilder(dataAdapterVendedor);
     comandBuilderVendedor.QuotePrefix = "[";
     comandBuilderVendedor.QuoteSuffix = "]";
     comandBuilderVendedor.RefreshSchema();
     dataSet = new System.Data.DataSet();
     try
     {
         conexion.Open();
         dataAdapterVendedor.Fill(dataSet);
         conexion.Close();
         dataViewVendedor.Table = dataSet.Tables["Vendedor"];
     }
     catch (SqlException)
     {
         lblError.Text = "Los datos no se han cargado correctamente";
     }
     return dataViewVendedor;
 }
开发者ID:SyedArifulIslamEmon,项目名称:Ending-Project-ASP.NET--Billing-system,代码行数:33,代码来源:Default.aspx.cs

示例7: cargaVistaStock

 /*Esta función es la encargada de en MODO DESCONECTADO, cargar el Stock de la BD
 *y devolvernos un DataView que manipularemos a posteriori*/
 protected DataView cargaVistaStock()
 {
     limpiarLablesError();
     SqlConnection conexion;
     DataSet dataSet;
     String sentencia;
     SqlDataAdapter dataAdapterStock;
     DataView dataViewStock = new DataView();
     SqlCommandBuilder comandBuilderStock;
     string cadenaConexion = System.Configuration.ConfigurationManager.ConnectionStrings["DB_FACTURACION"].ConnectionString;
     conexion = new SqlConnection(cadenaConexion);
     sentencia = "SELECT COD_PRO,Casa,Nombre,Descripcion,Familia,Precio,Imagen,Cantidad,CantidadMin FROM TB_Stock";
     dataAdapterStock = new System.Data.SqlClient.SqlDataAdapter(sentencia, conexion);
     dataAdapterStock.TableMappings.Add("Table", "Stock");
     comandBuilderStock = new System.Data.SqlClient.SqlCommandBuilder(dataAdapterStock);
     comandBuilderStock.QuotePrefix = "[";
     comandBuilderStock.QuoteSuffix = "]";
     comandBuilderStock.RefreshSchema();
     dataSet = new System.Data.DataSet();
     try
     {
         conexion.Open();
         dataAdapterStock.Fill(dataSet);
         conexion.Close();
         dataViewStock.Table = dataSet.Tables["Stock"];
     }
     catch (SqlException)
     {
         lblError.Text = "Los datos no se han cargado correctamente";
     }
     return dataViewStock;
 }
开发者ID:SyedArifulIslamEmon,项目名称:Ending-Project-ASP.NET--Billing-system,代码行数:34,代码来源:Default.aspx.cs


注:本文中的System.Data.SqlClient.SqlCommandBuilder.RefreshSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。