Overcoming Keyword Conflicts When Using CommandBuilders

[ Team LiB ] Recipe Overcoming Keyword Conflicts When Using CommandBuilders Problem Your data includes table and column names that conflict with SQL keywords. You can overcome this with brackets or quotes in SELECT statements that you write, but the CommandBuilder creates illegal update statements. | Team LiB Recipe Overcoming Keyword Conflicts When Using CommandBuilders Problem Your data includes table and column names that conflict with SQL keywords. You can overcome this with brackets or quotes in SELECT statements that you write but the CommandBuilder creates illegal update statements. You need to know how to use the CommandBuilder with your data. Solution Use the QuotePrefix and QuoteSuffix properties of the CommandBuilder object to delimit database server object names containing spaces or other illegal characters. The sample code contains two event handlers Preview Displays the delete insert and update commands using the delimiters specified by the user for the QuotePrefix and QuoteSuffix properties and either the OLE DB or SQL Server data provider as specified by the user. Retrieve OLE DB Uses the GetOleDbSchemaTable method of the OleDbConnection object to retrieve the default prefix and suffix delimiters for the data source. The C code is shown in Example 4-33. Example 4-33. File Namespaces variables and constants using System using using using using . . . private void previewButton_Click object sender e String sqlText SELECT OrderlD ProductID Quantity UnitPrice Discount FROM Order Details if Build the DataAdapter and the CommandBuilder. OleDbDataAdapter da new OleDbDataAdapter sqlText OleDb_ConnectString OleDbCommandBuilder cb new OleDbCommandBuilder da Set the prefix and suffix. Display CommandBuilder commands with the prefix and suffix. DeleteCommand .CommandText InsertCommand .CommandText UpdateCommand

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.