我刚才遇到跟你一样的问题,不过现在解决了原因就是数据库中该表没有PrimaryKey
手上有事,我就不给你分析你的代码了我把我的贴出来仅供参考(我的只用到更新所以只有UpdateCommand ,其他一样的)
using(SqlDataAdapter sda = new SqlDataAdapter("SELECT TD001,TD002,TD003,TD016 FROM COPTD",conn))
{
//SqlCommandBuilder scb = new SqlCommandBuilder(sda);
//sdaUpdateCommand = scbGetUpdateCommand();出错,跟你的一样
SqlCommand updateCmd = new SqlCommand("UPDATE COPTD SET TD016=@TD016 WHERE TD001=@TD001 AND TD002=@TD002 AND TD003=@TD003",sdaSelectCommandConnection);
updateCmdParametersAdd("@TD016",SqlDbTypeNVarChar,1,"TD016");
updateCmdParametersAdd("@TD001",SqlDbTypeNVarChar,4,"TD001");
updateCmdParametersAdd("@TD002",SqlDbTypeNVarChar,11,"TD002");
updateCmdParametersAdd("@TD003",SqlDbTypeNVarChar,4,"TD003");
sdaUpdateCommand = updateCmd;
rtl = sdaUpdate(dataSet,"COPTD");
}
帮你做了个,请采纳
添加附件失败,只有贴代码了
private void btn_Add_Click(object sender, EventArgs e){
KnowLedge kk = new KnowLedge();
kkSubject = cb_SubjectText;
kkKnow = rtb_KnowText;
kkPicturePath = pic_KnowImageLocation;
AddNewKnowLedge(kk);
Form1_Load(null,null);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“知识库Knowledge”中。您可以根据需要移动或删除它。
thisknowledgeTableAdapterFill(this知识库Knowledge);
}
public OleDbConnection getConnection()
{
OleDbConnection conn = null;
try
{
string connectionstr = @"Provider=MicrosoftACEOLEDB120;Data Source=|DataDirectory|\DBaccdb;Persist Security Info=True";
conn = new OleDbConnection(connectionstr);
connOpen();
}
catch (Exception e)
{
ConsoleWriteLine(eMessage);
}
return conn;
}
public void closeconnection(OleDbConnection conn)
{
try
{
connClose();
}
catch (Exception e)
{
}
}
public class KnowLedge
{
public string Subject = "";
public string Know = "";
public string PicturePath = "";
}
public void AddNewKnowLedge(KnowLedge kk)
{
byte[] myByte = new byte[0];
try
{
FileStream filestream = new FileStream(thispic_KnowImageLocation, FileModeOpen, FileAccessRead);
BinaryReader binaryReader = new BinaryReader(filestream);
myByte = new byte[filestreamLength];
binaryReaderRead(myByte, 0, ConvertToInt32(filestreamLength));
filestreamClose();
}
catch { }
OleDbConnection conn = getConnection();
OleDbCommand command = new OleDbCommand();
commandConnection = conn;
commandCommandText = @"insert into Knowledge(Subject,Know,Picture)values('" + kkSubject + "','" + kkKnow + "',@photo1)";
commandCommandType = CommandTypeText;
OleDbParameter imageType = new OleDbParameter("@photo1", OleDbTypeVarBinary);
imageTypeValue = myByte;
commandParametersAdd(imageType)Value = myByte;
try
{
commandExecuteNonQuery();
MessageBoxShow("添加成功");
}
catch (Exception ex)
{
MessageBoxShow(exMessage, "添加失败");
}
closeconnection(conn);
}
private void pic_Know_Click(object sender, EventArgs e)
{
OpenFileDialog _dialog = new OpenFileDialog();
_dialogFilter =
"All Image Files|bmp;ico;gif;jpeg;jpg;png;tif;tiff|" +
"Windows Bitmap(bmp)|bmp|" +
"Windows Icon(ico)|ico|" +
"Graphics Interchange Format (gif)|(gif)|" +
"JPEG File Interchange Format (jpg)|jpg;jpeg|" +
"Portable Network Graphics (png)|png|" +
"Tag Image File Format (tif)|tif;tiff";
if (DialogResultOK == _dialogShowDialog(this))
{
pic_KnowImageLocation = _dialogFileName;
}
}
private void dgv_mes_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//pic_KnowImage=Convertto(dgv_mesCurrentRowCells["Picture"]);
string id = dgv_mesCurrentRowCells["Col_ID"]ValueToString();
string sql = "select from Knowledge where ID=" + intParse(id);
DataSet ds = new DataSet();
OleDbConnection conn = getConnection();
OleDbDataAdapter oda = new OleDbDataAdapter(sql, conn);
odaFill(ds);
byte[] img = new byte[0];
if (ds != null)
{
DataRow dr = dsTables[0]Rows[0];
if (!dr["Picture"]ToString()Equals(""))
{
img = (byte[])dr["Picture"];
try
{
MemoryStream stream = new MemoryStream(img, true);
streamWrite(img, 0, imgLength);
pic_KnowImage = new Bitmap(stream);
}
catch { }
}
if (!dr["Know"]ToString()Equals(""))
{
rtb_KnowText = dr["Know"]ToString();
}
if (!dr["Subject"]ToString()Equals(""))
{
cb_SubjectText = dr["Subject"]ToString();
}
}
closeconnection(conn);
}
private void btn_Find_Click(object sender, EventArgs e)
{
string sql = "select from Knowledge where Know like '%" + rtb_KnowText + "%' and Subject like '%" + cb_SubjectText + "%' ";
DataSet ds = new DataSet();
OleDbConnection conn = getConnection();
OleDbDataAdapter oda = new OleDbDataAdapter(sql, conn);
odaFill(ds);
dgv_mesDataSource=dsTables[0];
}
//首先引入
using SystemData;
using SystemDataOleDb;
OleDbConnection con = new OleDbConnection("Provider=MicrosoftJetOleDb40;Data Source=F:\tem\green_for_testmdb"); //然后实例化数据库连接对象,其中Data Source=后面是你access数据库的路径
OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT FROM access_database", con); //要查询的话就实例化OleDbDataAdapter对象,里面两个参数分别是你的sql语句,上面实例化的数据库连接对象con,OleDbDataAdapter对象会自动管理连接对象的关闭
DataTable table = new DataTable(); //然后定义datatable对象,用于存放查询结果
AdapterFill(table); //通过Adapter 对象的Fill方法执行查询,同时将结果放入table中
datagridviewDataSource = table; //然后就是将table绑定到datagridview中
//完成,希望能帮到你
1 Aocoda飞控是一种品牌。
2 Aocoda飞控是一种用于遥控飞机的电子设备,可以控制飞机的飞行和稳定性。
它采用先进的飞行控制算法和传感器技术,并且具有高性能、高可靠性和易安装的特点,因此备受广大无人机爱好者的青睐。
3 Aocoda飞控的功能不仅限于遥控飞机,还可以应用于其他领域,例如航拍、测绘、农业、安防等。
它的出现使得无人机的控制更加简单和高效。
namespace DataFrm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=MicrosoftACEOLEDB120;Data Source=F:\\project\\office\\testaccdb");
OleDbCommand cmd=new OleDbCommand("selsect from list where num = '"+ textBox1Text + "'");
DataTable tb = new DataTable();
OleDbDataAdapter oda = new OleDbDataAdapter(cmd);
tbClear();
connOpen();
odaFill(tb);
textBox2Text = tbColumns["t"]ToString();
textBox3Text = tbColumns["area"]ToString();
connClose();
}
}
}
odaUpdate(dto);
或者
odaUpdate(dtp);
时,DataTable 里已经有相同的记录了,而且由于该DataTable 设置了“索引,主键,或关系值”,使得记录不能重复。最好在这里加上try catch,跟踪调试一下oda与dto和dtp的值,是不是有重复的记录。
另外,建议楼主即那个2条数据库更新语句分开写成2个函数。不要用同一套变量,这样很容易出错。
以上就是关于selectCommand 不返回 任何键列信息,无法生成updatecommand全部的内容,包括:selectCommand 不返回 任何键列信息,无法生成updatecommand、用c#做个简单知识库管理系统,连接数据库,visual studio2015能打开并运行,两天完成、c#中如何连接access数据库,并将查询内容显示在datagridview中。我见答案后会测试,测试成功会给分的等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)