动态成员c#

编程入门 行业动态 更新时间:2024-10-23 14:19:37
本文介绍了动态成员c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个类,它允许我将数据插入到我传入该类的任何mysql表中。在大多数情况下,除了向sql查询添加参数外,我已经完成了所有工作。 我所做的是将列名/列类型的ArrayList传递给我的方法,然后我获取此数据并解析出来并从那里构建我的查询。我遇到的一个问题是,当向查询添加参数时,我无法弄清楚如何获取传入的数据并将其与MySqlDbType结合使用。 这是一个简短的片段 cmd.Parameters.Add(fldName,MySqlDbType.VarChar); //静态添加方式 这是我目前的代码库。就像一个简短的fyi,数组列表是一个多维的arraylist。我知道下面的代码是错误的,现在确定如何使用字符串fldType作为MySqlDbType的成员。

展开 | 选择 | 换行 | 行号

解决方案

您是否考虑过使用cmd.Parameters.AddWithValue()? 然后您会说: cmd.Parameters.AddWithValue( MyParamName,MyParamVal UE); 它决定从传递给MyParamValue 卫生署,没有我不是有心对象类型正确的SQL类型甚至关于使用AddWithValue的事情。 现在它按照我想要的方式工作。谢谢你的帮助。

这确实为我打开了另一个问题。 在我的应用程序中的另一点,我必须使用与上述问题类似的东西。 我必须使用动态成员为了提取数据。 这是我正在测试的代码。 qbFld是我想从quickbooks中提取的字段名称文件。只是不确定如何创建一个动态成员。

展开 | 选择 | Wrap | 行号

I am working on a class that will allow me to insert data into any mysql table that I pass into the class. For the most part I have everything done except for adding parameters to the sql query. What I have done is pass an ArrayList of column names/ column types into my method, and then I take this data and parse it out and build my query from there. The one issue I have is, when adding parameters to the query, I am unable to figure out how to take the data I passed in and use it in conjunction with MySqlDbType. Here is a short snippet cmd.Parameters.Add(fldName, MySqlDbType.VarChar); // static way to add Here is my current code base. Just as a short fyi, the array list is a multidimensional arraylist. I know the code below is wrong, just now sure how to use the string fldType as a member of MySqlDbType.

Expand|Select|Wrap|Line Numbers

解决方案

Have you considered using cmd.Parameters.AddWithValue() instead? Then you would say: cmd.Parameters.AddWithValue(MyParamName,MyParamVal ue); It determines the correct sql type from the object type passed to MyParamValue

Doh, no I didn''t even thing about using AddWithValue. Now it works the way that I want it to. Thank you for your help.

This does open another question for me though. At another point in my app, I have to use something similar to my question above. I have to use a dynamic member in order to pull data. Here is the code I am testing with. qbFld is the field name I want to pull from the quickbooks file. Just not sure how to create a dynamic member.

Expand|Select|Wrap|Line Numbers

更多推荐

动态成员c#

本文发布于:2023-07-29 08:47:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239208.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:成员   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!