Tag: C#的

通过索引获取列表框项目的值

这一定很容易,但我被卡住了。 我有一个X项目列表框。 每个项目都有一个文本说明(出现在列表框中)及其值(数值)。 我希望能够获得项目的价值属性,使用项目的索引号。

如何形成一个正确的MySQL连接string?

我正在使用C#,我试图连接到00webhost托pipe的MySQL数据库。 我得到错误的线connection.Open() : 这个参数没有mysql主机。 我已经检查,一切似乎都很好。 string MyConString = "SERVER=mysql7.000webhost.com;" + "DATABASE=a455555_test;" + "UID=a455555_me;" + "PASSWORD=something;"; MySqlConnection connection = new MySqlConnection(MyConString); MySqlCommand command = connection.CreateCommand(); MySqlDataReader Reader; command.CommandText = "INSERT Test SET lat=" + OSGconv.deciLat + ",long=" + OSGconv.deciLon; connection.Open(); Reader = command.ExecuteReader(); connection.Close(); 这个连接string有什么问题?

linq实体不承认一个方法

我有这些方法: public int count( Guid companyId, Expression<Func<T, bool>> isMatch) { var filters = new Expression<Func<T, bool>>[]{ x => x.PriceDefinition.CompanyId == companyId, isMatch }; return GetCount(filters); } public virtual int GetCount( IEnumerable<Expression<Func<T, bool>>> filters) { IQueryable<T> _query = ObjectSet; if (filters != null) { foreach (var filter in filters) { _query = _query.Where(filter); } } return […]

如何通过ODBC C#绑定参数?

我需要绑定来自C#的ODBC查询参数。 这是示例代码,但VS告诉我,有一个参数丢失。 OdbcCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM user WHERE id = @id"; cmd.Parameters.Add("@id", OdbcType.Int).Value = 4; OdbcDataReader reader = cmd.ExecuteReader(); 什么是在ODBC上绑定值的语法?

你如何使用非默认构造函数的成员?

我有两个class class a { public: a(int i); }; class b { public: b(); //Gives me an error here, because it tries to find constructor a::a() a aInstance; } 我怎样才能得到它,使aInstance实例化(int我),而不是试图寻找一个默认的构造函数? 基本上,我想从b的构造函数中控制a的构造函数的调用。

C / C ++:优化指向string常量的指针

看看这个代码: #include <iostream> using namespace std; int main() { const char* str0 = "Watchmen"; const char* str1 = "Watchmen"; char* str2 = "Watchmen"; char* str3 = "Watchmen"; cerr << static_cast<void*>( const_cast<char*>( str0 ) ) << endl; cerr << static_cast<void*>( const_cast<char*>( str1 ) ) << endl; cerr << static_cast<void*>( str2 ) << endl; cerr << static_cast<void*>( […]

为什么DateTime.AddHours似乎不工作?

我有同样的结果1338161400 DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime date = DateTime.Parse(@"28/05/12 01:30"); TimeSpan diff = date.ToUniversalTime() – origin; Console.WriteLine( (Math.Floor(diff.TotalSeconds)).ToString()); 以及当我使用date.AddHours(-4): DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime date = DateTime.Parse(@"28/05/12 01:30"); date.AddHours(-4); TimeSpan diff = date.ToUniversalTime() – origin; Console.WriteLine( (Math.Floor(diff.TotalSeconds)).ToString()); 我试图得到1338168600像http://www.mbari.org/staff/rich/utccalc.htm 更新: 谢谢,我改变了 DateTime […]

为什么在列表<>中添加新值会覆盖列表<>中的以前的值

继几个教程后,我能够成功创build一个集合类,它inheritance创build一个DataTable所需的function,该DataTable可以作为表值parameter passing给Sql Server的存储过程。 一切似乎都运作良好; 我可以添加所有行,看起来很漂亮。 但是,仔细观察后,我注意到当我添加一个新行时,所有前面的行的数据被新行的值覆盖。 所以,如果我有一个string值为“foo”的行,并添加了第二行的值“bar”,第二行将被插入(使两行DataTable),但两行将有值“bar ”。 任何人都可以看到这是为什么? 下面是一些代码,它的工作原理虽然简单一些(为了便于说明,标签类已经缩小了)。 以下是Collection类的: using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using Microsoft.SqlServer.Server; namespace TagTableBuilder { public class TagCollection : List<Tag>, IEnumerable<SqlDataRecord> { IEnumerator<SqlDataRecord> IEnumerable<SqlDataRecord>.GetEnumerator() { var sdr = new SqlDataRecord( new SqlMetaData("Tag", SqlDbType.NVarChar) ); foreach (Tag t in this) { sdr.SetSqlString(0, t.tagName); yield return […]

如何在C#中备份和恢复系统剪贴板?

我会尽我所能详细解释我想要达到的目标。 我正在使用C#与IntPtr窗口句柄执行从我自己的C#应用​​程序的外部应用程序的CTRL-C复制操作。 我必须这样做,因为没有办法直接使用GET_TEXT访问文本。 然后我在我的应用程序中使用该副本的文本内容。 这里的问题是,我现在已经覆盖了剪贴板。 我希望能够做的是: 备份可能由我自己以外的任何应用程序设置的剪贴板的原始内容。 然后执行复制并将值存储到我的应用程序中。 然后恢复剪贴板的原始内容,以便用户仍然可以访问他/她的原始剪贴板数据。 这是我迄今为止所尝试的代码: private void GetClipboardText() { text = ""; IDataObject backupClipboad = Clipboard.GetDataObject(); KeyboardInput input = new KeyboardInput(this); input.Copy(dialogHandle); // Performs a CTRL-C (copy) operation IDataObject clipboard = Clipboard.GetDataObject(); if (clipboard.GetDataPresent(DataFormats.Text)) { // Retrieves the text from the clipboard text = clipboard.GetData(DataFormats.Text) as string; } if (backupClipboad […]

在两个应用程序间共享内存

我有两个不同的Windows应用程序(两个不同的人写代码)。 一个用C ++编写,另一个用C#编写。 我需要一些方法来在它们之间共享RAM中的数据。 一个人必须写数据,另一个只读数据。 我应该用什么来使其最有效和快速? 谢谢。