oledbcommand

OleDB update command not changing data

亡梦爱人 提交于 2019-12-02 04:58:34
I'm using Microsoft Access file as database. I have no problem with SELECT and INSERT queries but when I try to UPDATE , record in database does not change. Below is the code I use to run update. There are no exceptions or errors in debug log. cnn = new OleDbConnection(connetionString); OleDbCommand command = new OleDbCommand("UPDATE [Wpisy] SET [wpis]=@wpis, [id_kat]=@id_kat, [tytul]=@tytul WHERE [ID]=@id_wpis" , cnn); command.Parameters.Add(new OleDbParameter("@wpis", tresc_wpisu.Text)); command.Parameters.Add(new OleDbParameter("@id_kat", lista_kategorii.SelectedValue)); command.Parameters

Syntax error in INSERT statement into MS Access

烈酒焚心 提交于 2019-12-02 04:26:37
问题 I couldn't find the syntax error in the following INSERT statement. public partial class doRegister : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\database"; using (OleDbConnection con = new OleDbConnection(str)) using (OleDbCommand cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO users (staffID,accessLevelIdD,username,password,email) VALUES (@staffID, '2', @username,@password,@email)";

Syntax error in INSERT statement into MS Access

末鹿安然 提交于 2019-12-02 01:19:02
I couldn't find the syntax error in the following INSERT statement. public partial class doRegister : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\database"; using (OleDbConnection con = new OleDbConnection(str)) using (OleDbCommand cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO users (staffID,accessLevelIdD,username,password,email) VALUES (@staffID, '2', @username,@password,@email)"; cmd.Parameters.AddWithValue("@staffID", Request.Form["staffid"]); cmd.Parameters.AddWithValue("@password

Undefined function 'Replace' in expression , Replace alternative?

。_饼干妹妹 提交于 2019-12-01 08:56:48
as read in this question : Undefined function 'Replace' in expression , I'm getting the error "Undefined function 'Replace' in expression" because "you aren't using the Access query engine at all", but what do I use as an alternative ? Apparantly "a combination of Iif, Instr" would work, but I can't find out a way to actually replace something with these. All I want is to remove the spaces out of a value, how would I do this? const string strSql = "SELECT TOP 15 HOOFDGROEP.HOOFDGROEP, SUBGROEP.SUBGROEP, Artikels.*" + " FROM (Artikels LEFT JOIN HOOFDGROEP ON Artikels.HOOFDGROEPID = HOOFDGROEP

Error in executing an OleDbCommand.. “Must declare the scalar variable ”@MaxID“.”

三世轮回 提交于 2019-12-01 08:51:18
private void AddValue(string strValue) { //get the maximum id for Lists first int MaxID = DataOperations.ReturnMaxIDInATable("Lists", connString); int iSqlStatus = 0; string query = "INSERT INTO Lists(ID, ListName, ListValue) VALUES(@MaxID, @ListName, @ListValue)"; MaxID++; OleDbConnection dbConn = new OleDbConnection(connString); OleDbCommand dbComm = new OleDbCommand(); dbComm.Parameters.Clear(); try { dbComm.CommandText = query; dbComm.CommandType = CommandType.Text; OleDbParameter IDParam = new OleDbParameter(); IDParam.ParameterName = "@MaxID"; IDParam.OleDbType = OleDbType.BigInt;

Undefined function 'Replace' in expression , Replace alternative?

六眼飞鱼酱① 提交于 2019-12-01 07:39:36
问题 as read in this question : Undefined function 'Replace' in expression , I'm getting the error "Undefined function 'Replace' in expression" because "you aren't using the Access query engine at all", but what do I use as an alternative ? Apparantly "a combination of Iif, Instr" would work, but I can't find out a way to actually replace something with these. All I want is to remove the spaces out of a value, how would I do this? const string strSql = "SELECT TOP 15 HOOFDGROEP.HOOFDGROEP,

SSIS - Updating a table with a OLE DB Command

牧云@^-^@ 提交于 2019-11-28 13:57:50
I need to translate the next SQL Query in SSIS: (Each table belong to a different source - SQL Server & ORACLE) update A set A.col1 = B.col1 A.col2 = B.col1 from table A inner join table B B on A.col3 = Col3 where A.col4 = value 1 and A.col5 = value2 and B.col4 = value 3; As you can see, source and destination corresponds to the same source: table A. This is the work flow I have created. After the conditional split I have used a Derived Column in order to copy the column B.Col1 to use it on the OLE DB Command to update the columns of table A After that, I have write the next piece of query in

insert into access database

我与影子孤独终老i 提交于 2019-11-28 13:47:07
i have trouble inserting data from textbox into ms access database, I get an error " Syntax error in INSERT INTO. " Can someone help me out please? here's the code: public void button1_Click(object sender, EventArgs e)//save { using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\productdb.mdb")) { OleDbCommand CmdSql = new OleDbCommand("Insert into [product](Kod, names, price,type,volume,manufacturer,importer) enter code here { conn.Open(); CmdSql.Parameters.AddWithValue("@Kod", textBox1.Text); CmdSql.Parameters.AddWithValue("@names",

How to use SQL user defined functions in .NET?

吃可爱长大的小学妹 提交于 2019-11-28 10:09:05
I created a scalar function in the DB SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[fn_GetUserId_Username] ( @Username varchar(32) ) RETURNS int AS BEGIN DECLARE @UserId int SELECT @UserId = UserId FROM [User] WHERE Username = @Username RETURN @UserId END Now I want to run it within my .NET C# or VB.NET code. I use Entity Framework, I tried to map it with function mapping and I did not success. i don't care to do it with simple DbCommand, the problem is that I get no results (the function exists in the Entities class): public int GetUserIdByUsername(string username) {

Is order of parameters for database Command object really important?

空扰寡人 提交于 2019-11-27 16:14:52
I was debugging a database operation code and I found that proper UPDATE was never happening though the code never failed as such. This is the code: condb.Open(); OleDbCommand dbcom = new OleDbCommand("UPDATE Word SET word=?,sentence=?,mp3=? WHERE id=? AND exercise_id=?", condb); dbcom.Parameters.AddWithValue("id", wd.ID); dbcom.Parameters.AddWithValue("exercise_id", wd.ExID); dbcom.Parameters.AddWithValue("word", wd.Name); dbcom.Parameters.AddWithValue("sentence", wd.Sentence); dbcom.Parameters.AddWithValue("mp3", wd.Mp3); But after some tweaking this worked: condb.Open(); OleDbCommand dbcom