我从DataSet获取DataTable,然后将该DataTable绑定到DataGridView.一旦用户编辑DataGridView上的信息,我该如何处理这些更改并将它们放回到使用的DataTable中,然后我可以将其放回到我的DataSet中?
我想在我的DataGrid上创建一个Save Button,当按下时实际上保存了更改.
如果我能得到更具体的话,我不会,因为这是一个相当简单的问题.
提前致谢!
如果您需要我详细说明,请告诉我.
我刚刚发布了一个关于如何让代理人在另一个表单上更新文本框的问题.就在我以为我有使用Invoke的答案时...这种情况发生了.这是我的代码:
主表格代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Data.OleDb;
using System.Collections.Specialized;
using System.Text;
using System.Threading;
delegate void logAdd(string message);
namespace LCR_ShepherdStaffupdater_1._0
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
public void add(string message)
{
this.Log.Items.Add(message);
}
public void logAdd(string message)
{ /////////////////////////// COMPILER ERROR BELOW ///////////
this.Invoke(new logAdd(add), new object[] { message }); // Compile error occurs here
}////////////////////////////// COMPILER ERROR ABOVE ///////////
private void exitProgramToolStripMenuItem_Click(object …Run Code Online (Sandbox Code Playgroud) 以下用于创建全局对象导致编译错误.
#include "stdafx.h"
#include <iostream>
using namespace System;
using namespace std;
#pragma hdrstop
class Tester;
void input();
class Tester
{
static int number = 5;
public:
Tester(){};
~Tester(){};
void setNumber(int newNumber)
{
number = newNumber;
}
int getNumber()
{
return number;
}
}
Tester testerObject;
void main(void)
{
cout << "Welcome!" << endl;
while(1)
{
input();
}
}
void input()
{
int newNumber = 0;
cout << "The current number is " << testerObject.getNumber();
cout << "Change number to: "; …Run Code Online (Sandbox Code Playgroud) 我的代码有效.复制约10个表后,我收到错误.Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.好的,我知道我需要生成一个主键.但为什么我可以复制10个左右的表,然后我得到错误.每行都必须返回主键吗?如果一行没有主键,我该如何生成一个?
这是我的代码:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Text;
namespace LCR_ShepherdStaffupdater_1._0
{
public class DatabaseHandling
{
static DataTable datatableB = new DataTable();
static DataTable datatableA = new DataTable();
public static DataSet datasetA = new DataSet();
public static DataSet datasetB = new DataSet();
static OleDbDataAdapter adapterA = new OleDbDataAdapter();
static OleDbDataAdapter adapterB = …Run Code Online (Sandbox Code Playgroud) 我正在做的项目差不多完成了.我正在加载.MDB文件,在DataGrid上显示内容并尝试在DataGrid上获取这些更改并将它们保存回.MDB文件.我还将创建一个函数,允许我从一个.MDB文件中获取表并将其保存到另一个.MDB文件中.当然,如果我无法弄清楚如何将更改保存回.MDB文件,我就无法做到这一点.
我对Google进行了广泛的研究,但我的问题没有答案.我认为自己是这个特定主题的初学者所以请不要让答案太复杂 - 我需要最简单的方法来编辑.MDB文件!请提供编程示例.
提前感谢您,如果您需要更多信息,请与我们联系.这是我可能不得不问这个话题的最后一件事......感谢上帝.
编辑:
我正在使用的.mdb是一个Microsoft Access数据库.(我甚至不知道有多个.mdb文件)
我知道我不能通过编写器或任何东西直接写入.MDB文件,但有没有办法可以生成一个带有DataSet信息的.MDB文件?或者只是一种方法,我可以将表添加到我已经加载到DataGrid的.MDB文件中.有办法!
同样,我需要一种在C#中以编程方式执行此操作的方法.
编辑:
好的,我的项目相当大,但我使用一个单独的类文件来处理所有数据库连接.我知道我的设计和来源非常邋,,但它完成了工作.我和互联网上的例子一样好.
请记住,我只是以另一种形式连接到DataGrid.如果你想要我的代码来自Datagrid表单,请告诉我(我不知道为什么你会需要它).DatabaseHandling.cs处理2个.MDB文件.所以你会看到两个数据集.我最终将使用它来从一个数据集中获取表并将它们放入另一个数据集中.我只需要弄清楚如何将这些值保存到.MDB文件中.
反正有没有这样做?必须有办法...
编辑:
从我研究和阅读的内容......我认为答案就在我的鼻子底下.使用"Update()"命令.现在虽然这是重新确保实际上有一个简单的方法,我仍然留下问题,我没有friggin线索如何使用此更新命令.
也许我可以像这样设置它:
Oledb.OledbConnection cn = new Oledb.OledbConnection();
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Staff.mdb";
Oledb.OledbCommand cmd = new Oledb.OledbCommand(cn);
cmd.CommandText = "INSERT INTO Customers (FirstName, LastName) VALUES (@FirstName, @LastName)";
Run Code Online (Sandbox Code Playgroud)
我认为可能会这样做,但我不想手动插入任何东西.我想要做这两件事:
我希望有人能为此提出答案......我的项目已经完成所有等待的答案就是一个简单的答案.
提前再次感谢您.
编辑:
好的...好消息 我已经想出如何查询.mdb文件本身(我认为).这是代码,它不起作用,因为我试图使用的sql命令导致运行时错误.这将带我到我的下一个问题.
添加到DatabaseHandling.cs的新功能代码:
static public void performSynchronization(string table, string tableTwoLocation)
{
OleDbCommand cmdCopyTables = new OleDbCommand("INSERT INTO" + table + "SELECT * FROM [MS Access;" + tableTwoLocation …Run Code Online (Sandbox Code Playgroud) 这是我的第一个问题之一.每当我退出程序时,tcpClient.Connect()都会永远关闭.我尝试了很多东西,但似乎都没有.
看一下CreateConnection()线程,如果客户端还没有连接......我关闭程序,它需要永远关闭.如果已连接,则立即关闭.我知道这可以通过某种超时技巧来完成,但我已经尝试了一些,但没有一个工作.
如果可以,请提供代码示例.
另外,C#在读取/写入实际字节时是否有一个很好的教程,而不是只有masterServer.writeLine()和masterServer.readline()的版本,或者它们都同样有效吗?
如果你看到其他任何东西可以帮助我改善这一点......无论如何,请继续.我正在努力教自己如何做到这一点,我没有任何帮助,所以如果你看到它,不要让我继续做错事!多谢你们!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
namespace RemoteClient
{
public partial class Form1 : Form
{
private int MyPort = 56789;
private IPAddress myIp = IPAddress.Parse("210.232.115.79");
private IPAddress serverIp = IPAddress.Parse("72.216.18.77"); // Master Server's IP Address
public static TcpClient masterServer = new TcpClient();
private StreamWriter responseWriter;
private StreamReader commandReader;
private Thread connectionThread;
private Thread commandsThread;
private bool …Run Code Online (Sandbox Code Playgroud) 我正在尝试读取二进制数据以将结构加载回内存,以便我可以编辑它们并将它们保存回.dat文件.
readVector()尝试读取文件,并返回序列化的向量.但是当我尝试运行它时,我收到了这个编译错误.我的模板出了什么问题?
*********编辑******************
码:
// Project 5.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace System;
using namespace std;
#pragma hdrstop
int checkCommand (string line);
template<typename T>
void writeVector(ofstream &out, const vector<T> &vec);
template<typename T>
vector<T> readVector(ifstream &in);
struct InventoryItem {
string Item;
string Description;
int Quantity;
int wholesaleCost;
int retailCost;
int dateAdded;
} ;
int main(void)
{
cout << "Welcome to the Inventory Manager extreme! [Version 1.0]" << endl; …Run Code Online (Sandbox Code Playgroud) 由于你们大多数人可能都在关注我已经知道的问题,我正在尝试创建一个程序,可以将多个结构序列化为.dat文件,通过加载它的序列化来读取它们,编辑内容,然后重新将它们写入文件等等.这是我正在尝试做的库存计划,我不能让它为我的生活工作.
我正在加载的文件是空白的.我的程序需要10秒甚至加载,现在我知道为什么.这是因为我的矢量大小就像25万.哦等等......这次我跑了它的矢量大小是5,172,285.这是一个充满结构的相当大的向量.没有任何运行时或编译错误,但我很确定我做错了什么.我正在加载的文件也是完全空白的.
码:
// Project 5.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace System;
using namespace std;
#pragma hdrstop
int checkCommand (string line);
template<typename T>
void writeVector(ofstream &out, const vector<T> &vec);
template<typename T>
vector<T> readVector(ifstream &in);
struct InventoryItem {
string Item;
string Description;
int Quantity;
int wholesaleCost;
int retailCost;
int dateAdded;
} ;
int main(void)
{
cout << "Welcome to the Inventory Manager extreme! [Version 1.0]" << endl;
ifstream …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我正在处理的项目创建自己的错误窗口.当我显示我的错误窗口时,我无法将错误消息和用户消息传递给错误窗口,因为在我创建的类中无法看到"ErrorMessage.Text".
我进入了表单设计器生成的代码并尝试使TextBox保持静态,但这只会破坏事物.我可以将TextBox设为public/static,以便我可以从另一个表单中更改它吗?
编辑:
好的,有关更多信息......
我创建了自己的表单.它被称为"formErrorWindow".我需要显示我使用其他表单中的消息集预先设计的表单.我能做到这一点的唯一方法是,如果我在窗体设计器区域中为窗体创建一个Function,并使用"this.errorMsg.text = error"设置变量.我能看到该功能的唯一方法是将其设置为静态.如果我将函数设置为静态,当我尝试将"this.errorMsg.Text = error"时,我得到此错误:非静态字段,方法或属性需要对象引用.
这是我尝试过的:
namespace LCR_ShepherdStaffupdater_1._0
{
partial class formErrorWindow
{
/// <summary>
/// Required designer variable.
/// </summary>
public System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
///
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code …Run Code Online (Sandbox Code Playgroud) 我一直在努力让这个程序完成,它将多个结构保存到文件中,可以将它们读回并编辑它们,然后将它们全部保存回文件.我一直在研究这个逻辑,更不用说其他人的大量帮助和大量的谷歌搜索时间......现在我收到编译错误.任何帮助将非常感激.
码:
template<typename T>
void writeVector(ofstream &out, const vector<T> &vec);
struct InventoryItem {
string Item;
string Description;
int Quantity;
int wholesaleCost;
int retailCost;
int dateAdded;
} ;
int main(void)
{
vector<InventoryItem> structList;
ofstream out("data.dat");
writeVector( out, structList );
return 0;
}
template<typename T>
void writeVector(ofstream &out, const vector<T> &vec)
{
out << vec.size();
for(vector<T>::const_iterator i = vec.begin(); i != vec.end(); i++)
{
out << *i; // error C2679
}
}
Run Code Online (Sandbox Code Playgroud)
编译错误:
1>.\Project 5.cpp(128) : error C2679: binary '<<' : no …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 HyperLedger Fabric 构建我的第一个网络,但遇到了一个错误,我一直在坚持。我在本教程的“创建和加入”部分:构建您的第一个网络
此控制台命令出现错误:
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Run Code Online (Sandbox Code Playgroud)
我收到此错误:“错误:无法创建交付客户端:订购者客户端无法连接到 orderer.example.com:7050:无法创建新连接:超出上下文截止时间”
这是我的控制台错误和失败的订购者的日志的屏幕截图:
有人会帮助我修复此错误,以便我的对等方连接到订购者客户端吗?谢谢!