Fetch value and display to comboBox
Hi anyone can help me.
I want to retrieve data from my table and display it to combBox but i wont display. But when i switch to textBox it will display.
Code:
OleDbDataReader reader = cm.ExecuteReader();
while (reader.Read())
{
dataGridView2.Rows.Add(
reader["Employee Name"].ToString());
Datagridview:
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
try
{
connection.Open();
OleDbCommand cm = new OleDbCommand();
cm.Connection = connection;
cm.CommandText = query;
OleDbDataReader reader = cm.ExecuteReader();
while (reader.Read())
{
comboBox4.Text = dataGridView2.SelectedRows[0].Cells["Column8"].Value.ToString();
do you know?
how many words do you know
See also questions close to this topic
-
C# - Adding condition to func results in stack overflow exception
I have a func as part of specification class which sorts the given iqueryable
Func<IQueryable<T>, IOrderedQueryable<T>>? Sort { get; set; }
When i add more than one condition to the func like below , it results in stack overflow exception.
spec.OrderBy(sc => sc.Case.EndTime).OrderBy(sc => sc.Case.StartTime);
The OrderBy method is implemented like this
public ISpecification<T> OrderBy<TProperty>(Expression<Func<T, TProperty>> property) { _ = Sort == null ? Sort = items => items.OrderBy(property) : Sort = items => Sort(items).ThenBy(property); return this; }
Chaining or using separate lines doesn't make a difference.
This problem gets resolved if I assign a new instance of the specification and set it's func, but i don't want to be assigning to a new instance everytime. Please suggest what am i missing here and how to reuse the same instance (if possible).
-
How to projection fields for a dictionary (C#, MongdoDB)
I am trying my luck here, I have a model which is like the following
public class RowData : BaseBsonDefinition { . [BsonExtraElements] [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] public Dictionary<string, object> Rows { get; set; } = new(StringComparer.OrdinalIgnoreCase); . }
In result, the schema in the MongoDB looks like
{ "_id": { "$binary": { "base64": "HiuI1sgyT0OZmcgGUit2dw==", "subType": "03" } }, "c1": "AAA", "c8": "Fully Vac", "c10": "", }
Those c1, c8 and c10 fields are keys from the dictionary, my question is how to dynamic project those fields?
I tried
Builders<RowData>.Projection.Exclude(p => "c1")
It seems the MongoDB driver can not handle a value directly.
Anyone could point me in the correct direction?
Thanks,
-
How do I add new DataSource to an already Databinded CheckBoxList
i'm building a web form that show Database's item(Tables, Rows, FK,...)
I have a CheckBoxList of Tables (
chkListTable
) which will show a new CheckBoxList of Rows (chkListRow
) everytime I SelectedIndexChanged fromchkListTable
. The problem is i can show the items fromchkListTable
with 1 selected item. But i don't know how to showchkListRow
if multiple item fromchkListTable
are selected.Here are my codes:
aspx
:<div> <asp:Label ID="Label2" runat="server" Text="Table: "></asp:Label> <asp:CheckBoxList ID="chkListTable" runat="server" DataTextField="name" DataValueFeild="name" AutoPostBack="true" OnSelectedIndexChanged="chkListTable_SelectedIndexChanged"> </asp:CheckBoxList> </div> <div> <asp:CheckBoxList ID="chkListRow" runat="server" DataTextField="COLUMN_NAME" DataValueField="COLUMN_NAME" RepeatDirection="Horizontal"> </asp:CheckBoxList> </div>
aspx.cs
:protected void chkListTable_SelectedIndexChanged(object sender, EventArgs e) { tableName.Clear(); foreach (ListItem item in chkListTable.Items) { if(item.Selected) { tableName.Add(item.Text.Trim()); } } for(int i = 0; i < tableName.Count; i++) { String query = "USE " + dbname + " SELECT * FROM information_schema.columns" + " WHERE table_name = '" + tableName[i] + "'" + " AND COLUMN_NAME != 'rowguid'"; chkListRow.DataSource = Program.ExecSqlDataReader(query); chkListRow.DataBind(); Program.conn.Close(); } }
Program.cs
:public static bool Connect() { if (Program.conn != null && Program.conn.State == ConnectionState.Open) Program.conn.Close(); try { Program.conn.ConnectionString = Program.constr; Program.conn.Open(); return true; } catch (Exception e) { return false; } } public static SqlDataReader ExecSqlDataReader(String query) { SqlDataReader myreader; SqlCommand sqlcmd = new SqlCommand(query, Program.conn); sqlcmd.CommandType = CommandType.Text; if (Program.conn.State == ConnectionState.Closed) Program.conn.Open(); try { myreader = sqlcmd.ExecuteReader(); return myreader; myreader.Close(); } catch (SqlException ex) { Program.conn.Close(); return null; } }
I want my display to be like this:
[x]Table1 [x]Table2 [ ]Table3 [ ]Row1(Table1) [ ]Row2(Table1) [ ]Row3(Table1) [ ]Row1(Table2) [ ]Row2(Table2)
-
How i Read barcode and send emil information
I want when he writes the barcode upstairs, he writes downstairs. Information with also time and then sent on Email Direct without clicking any button
-
Rows[0].Visible command not working in WinForms C#
Hi i have simple method for cropping some rows in datagridview. But this code is not working. I tried to set unvisible some columns and datagridview, it worked well, but there is a problem on rows. There is my code, thanks for your comments.
private void cropDGV() { foreach (DataGridViewRow row in dataGridView.Rows) { if(Convert.ToInt32(row.Cells["enchantment"].Value) == 1) { CurrencyManager cm = (CurrencyManager)BindingContext[dataGridView.DataSource]; cm.SuspendBinding(); row.Visible = false; cm.ResumeBinding(); } } }
-
VBA QuickBooks: Class not registered
My long-time running MS Access application will no longer create QuickBooks invoices and is failing on the OpenConnection line with the following error:
HRESULT -2147221164 (8004154) Class not registered
My relevant code is:
Option Compare Database Public requestMsgSet As QBFC2Lib.IMsgSetRequest ' QB global variable Public booSessionBegun As Boolean ' QB global variable Public Response As QBFC2Lib.IResponse ' QB global variable Public responseMsgSet As QBFC2Lib.IMsgSetResponse ' QB global variable Public sessionManager As New QBFC2Lib.QBSessionManager ' QB global variable Public invoiceLineAdd As QBFC2Lib.IInvoiceLineAdd ' QB global variable Public invoiceAdd As QBFC2Lib.IInvoiceAdd ' QB global variable Public OrientIDHolder As Integer Public MultipleInvoice As Boolean ' QB global variable 'False until session is begun booSessionBegun = False ' Create the session manager object using QBFC 2.0, and use this ' object to open a connection and begin a session with QuickBooks. sessionManager.OpenConnection "AZENCODE02", "Database - QuickBooks invoice add" sessionManager.BeginSession "", QBFC2Lib.omDontCare booSessionBegun = True ' Session has begun
The error is in the
QuickBooks.sessionManager.OpenConnection
line but I cannot figure out what is happening. -
using DDE get a response from Python to VBA in MS Access
I have a need to pass strings back forth from a python script to a VBA application running in MS Access.
Communication from VBA to Python works great!
Communication from Python to VBA - not so great great...
The code runs without error, but I only get the 1st character of the response.
EX: Python returns "Joy" VBA only gets "J"
Keep in mind what is so frustrating is I can send strings from VBA to the Python script is no problem.
The Python DDE server:
import win32ui from pywin.mfc import object import dde class MySystemTopic(object.Object): def __init__(self): object.Object.__init__(self, dde.CreateServerSystemTopic()) def Exec(self, cmd): print("System Topic asked to exec", cmd) class recv_from_VBA_topic(object.Object): def __init__(self, topicName): object.Object.__init__(self, dde.CreateTopic(topicName)) def Exec(self, cmd): print("recv_VBA_CMD asked to exec", cmd) # print('sending back responce: ' + 'Dave is really great!!!!') class send_to_VBA_topic(object.Object): def __init__(self, topicName): topic = dde.CreateTopic(topicName) topic.AddItem(dde.CreateStringItem("")) object.Object.__init__(self, topic) def Request(self, aString): daLen = str(len(aString)) print("send_to_VBA_topic Request Topic asked to compute length of:", aString, daLen) return(daLen + ' : ' + aString) def main(): server = dde.CreateServer() server.AddTopic(MySystemTopic()) server.AddTopic(recv_from_VBA_topic("recv_VBA_CMD")) server.AddTopic(send_to_VBA_topic("send_to_VBA_topic")) server.Create('SDER_DDE') print('server: SDER_DDE\n Topic: recv_VBA_CMD\n Topic: send_to_VBA_topic\n') while 1: win32ui.PumpWaitingMessages(0, -1) if __name__ == "__main__": main()
The VBA code:
Option Compare Database Option Explicit Public Function dde_send(Optional strIn As String) As String Dim sRet As String Dim Blp As Long 'Blp = DDEInitiate("RunAny", "RunAnyCommand") Blp = DDEInitiate("SDER_DDE", "recv_VBA_CMD") If Not IsNull(strIn) Then Call DDEExecute(Blp, strIn) Else Call DDEExecute(Blp, "Greetings from VBA!") End If Call DDETerminate(Blp) dde_send = sRet End Function Public Function dde_recv(Optional strIn As String) As String Dim sRet As String Dim Blp As Long Dim vDDE As Variant, sDDE As String Blp = DDEInitiate("SDER_DDE", "send_to_VBA_topic") If Not IsNull(strIn) Then ' vDDE = DDERequest(Blp, strIn) sDDE = DDERequest(Blp, strIn) Debug.Print sDDE Else vDDE = DDERequest(Blp, "dde_recv test") End If DDETerminate (Blp) dde_recv = sDDE End Function
dde_send works dde_recv only gets the 1st character
NOTE: I tested the Python server with this code and it works for receiving the correct string back from the server.
import win32ui import dde #apparently "servers" talk to "servers" server = dde.CreateServer() #servers get names but I'm not sure what use this name #has if you're acting like a client server.Create("TestClient") #use our server to start a conversation conversation = dde.CreateConversation(server) # RunAny is the server name, and RunAnyCommand is the topic conversation.ConnectTo("SDER_DDE", "send_to_VBA_topic") # DoSomething is the command to execute # conversation.Exec("Dave is Great!") # For my case I also needed the request function # request somedata and save the response in requested_data. try: requested_data = conversation.Request("somedata") print(requested_data) except: print('conversation.Request: exception error')