|
|
I am writing in VB.NET, enhancing a working program. Part of the program involves getting data from various outside sources and saving it in tables in an Access database. I am adding a new outside source (for the first time for quite a while), and am tearing my hair out trying to get code that is working with previously created DataTables and their derivatives to work with a newly created set.
I used the dataset configuration facility to create a DataTable based on a Query from my new Access table. The Access query returns all the fields of recent records in the Table and is updateable in Access. The dataset query is
SELECT PriKey, ChannelNumber, ChannelName, ReadingDate, Power FROM qryRecentSpyderData
PriKey is an AutoNumber primary key. Other than different field names, I have an apparently identical setup working without problems in another function. The failing code is:
Dim dst1 As New EnergyDataSet
Dim tba1 As New EnergyDataSetTableAdapters.SpyderMinTableAdapter
Dim tbl1 As New EnergyDataSet.SpyderMinDataDataTable
Dim rowData() As EnergyDataSet.SpyderMinDataRow
Dim rowNew As EnergyDataSet.SpyderMinDataRow
...
For intCount = intStart To 0 Step -1
rowNew = tbl1.NewSpyderMinDataRow
rowNew.ChannelNumber = intChannel
rowNew.ChannelName = minhArray(intCount).strChannel
rowNew.ReadingDate = minhArray(intCount).dtSampleTime
rowNew.Power = minhArray(intCount).sngPower
tbl1.Rows.Add(rowNew)
Next
The Rows.Add line throws a "Nulls not allowed" exception the first time through the loop. If I relax constraints, it throws a "Duplicate Primary Key" exception the second time through. I know that I haven't set the Primary Key - Access will set it in due course! I cannot see why this fails, while essentially identical code using what appears to be an exactly comparable dataset succeeds. What am I missing?
|
|
|
|
|
Well, I have a workaround - if I delete the reference to the Primary Key field in the DataTableAdapter definition, the code works and the database does get updated properly when I .Update it from the table. Since I don't need access to the Primary Key in the VB.Net code for anything, this is acceptable, but I still don't understand why the older code, whose table definitions include the relevant Primary Keys, works.
|
|
|
|
|
I am trying to create a custom ValidationAttribute in my c# .net code. I have done a lot of searching and have code that should be working but the IsValid method is not firing as far as I can tell.
Model code:
[Required(AllowEmptyStrings = false, ErrorMessage = "required")]
[ValidYear(ErrorMessage="Please enter one >= 2014")]
[Display(Name = "Exp. Year")]
public string expYear { get; set; }
And this is the class in that same model:
public class ValidYearAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
return new ValidationResult("Something went wrong");
}
}
Hopefully someone can help figure out why the IsValid is not firing.
Thanks
Mike
|
|
|
|
|
Hi,
I am developing an application in c#.net where I need to include the accounting information/transactions along with other data.
How this can be done? Please help.
Thanks in advance,
Guru.
|
|
|
|
|
There is not enough information in your question to be able to offer a reasonable response. If you have a specific programming problem then please provide clearer details. If you wish to learn accountancy then this is probably not the best place.
|
|
|
|
|
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
con1.Open();
SqlCommand cmd4 = new SqlCommand("UPDATE candidate_personal_details SET GUARDIAN_NAME='" + TextBox23.Text + "',GUARDIAN_PH_NO='" + TextBox24.Text + "',GUARDIAN_MOB='" + TextBox25.Text + "',NATIONALITY='" + TextBox26.Text + "', GENDER='" + DropDownList1.Text + "',D_O_B='" + TextBox27.Text + "' , PRESENT_ADDRESS='" + TextBox28.Text + "',DIST1='" + TextBox29.Text + "' ,PIN1='" + TextBox30.Text + "',PERMANENT_ADDRESS='" + TextBox31.Text + "',DIST2='" + TextBox32.Text + "',PIN2='" + TextBox33.Text + "',LOCAL_GUARDIAN_NAME='" + TextBox34.Text + "',LOCAL_GUARDIAN_ADDRESS='" + TextBox35.Text + "' ,DIST3='" + TextBox36.Text + "',PIN3='" + TextBox37.Text + "' ,LOCAL_GUARDIAN_PH_NO='" + TextBox38.Text + "' ,LOCAL_GUARDIAN_MOB='" + TextBox39.Text + "'WHERE EMAIL_ID='" + TextBox21.Text + "'", con1);
SqlCommand cmd5 = new SqlCommand("UPDATE educational_details SET X_N_O_INSTITUTION='" + TextBox40.Text + "',X_N_O_BOARD='" + TextBox41.Text + "',X_Y_O_PASSING='" + TextBox42.Text + "',X_O_MARKS='" + TextBox43.Text + "',XII_N_O_INSTITUTION='" + TextBox45.Text + "',XII_N_O_BOARD='" + TextBox46.Text + "',XII_Y_O_PASSING='" + TextBox47.Text + "',XII_O_MARKS='" + TextBox48.Text + "',G_N_O_INSTITUTION='" + TextBox50.Text + "',G_N_O_BOARD='" + TextBox51.Text + "',G_Y_O_PASSING='" + TextBox52.Text + "',G_O_MARKS='" + TextBox53.Text + "'WHERE EMAIL_ID='" + TextBox21.Text + "'", con1);
// SqlCommand cmd3 = new SqlCommand(sql2, con);
cmd4.ExecuteNonQuery();
cmd5.ExecuteNonQuery();
con1.Close();
Label66.Text = "data is updated successfuly...";
// cmd3.ExecuteNonQuery();
}
|
|
|
|
|
Not surprising; add a space before the "WHERE" keyword. It'd be a bit more safe (google for Sql Injection) and a whole lot more readable if you use parameterized queries;
using (var con = new System.Data.SqlClient.SqlConnection())
using (var cmd = con.CreateCommand())
{
con.ConnectionString = "<insert your connectionstring here>";
con.Open();
cmd.CommandText = @"UPDATE candidate_personal_details
SET GUARDIAN_NAME=@GuardianName
,GUARDIAN_PH_NO=GuardianPhone
,GUARDIAN_MOB=@GuardianMobile
,NATIONALITY=@GuardianNationality
,GENDER=@GuardianGender
,D_O_B=@GuardianDob
,PRESENT_ADDRESS=@GuardianPresentAdress
,DIST1=@GuardianDist1
,PIN1=@GuardianIn1
,PERMANENT_ADDRESS=@GuardianAddress2
,DIST2=@GuardianDist2
,PIN2=@GuardianIn1
,LOCAL_GUARDIAN_NAME=@GuardianLocalName
,LOCAL_GUARDIAN_ADDRESS=@GuardianAddress3
,DIST3=@GuardianDist3
,PIN3=@GuardianIn1
,LOCAL_GUARDIAN_PH_NO=@GuardianPhone626 -- how many phones do they HAVE?
,LOCAL_GUARDIAN_MOB=@GuardianMob3
WHERE EMAIL_ID=@GuardianMailId";
cmd.Parameters.AddWithValue("@GuardianName", TextBox23.Text);
cmd.Parameters.AddWithValue("@GuardianPhone", TextBox24.Text);
cmd.Parameters.AddWithValue("@GuardianMobile", TextBox25.Text);
cmd.Parameters.AddWithValue("@GuardianNationality", TextBox26.Text);
cmd.Parameters.AddWithValue("@GuardianGender", TextBox27.Text);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.CommandText = @"UPDATE educational_details
SET X_N_O_INSTITUTION=@X_NO_Institution
,X_N_O_BOARD=@X_NO_Board
,X_Y_O_PASSING=X_Y_O..
WHERE EMAIL_ID=@GuardianMailId");
cmd.Parameters.AddWithValue("@GuardianName", TextBox23.Text);
cmd.Parameters.AddWithValue("@GuardianPhone", TextBox24.Text);
cmd.Parameters.AddWithValue("@GuardianMobile", TextBox25.Text);
cmd.Parameters.AddWithValue("@GuardianNationality", TextBox26.Text);
cmd.Parameters.AddWithValue("@GuardianGender", TextBox27.Text);
cmd.ExecuteNonQuery();
}
I'd strongly recommend to give the controls REAL names, like "GuardianNameTextBox" - it'd be a bit more friendly than having a "TextBox24" in there. It's also a non-normalized database. What happens when a "DIST4" is required?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
There May Be any DAtabase Name Mismatch Otherwirse Table Mismatch...
|
|
|
|
|
Ther is some Problem In your Code.You Should write like .
Int k=cmd3.ExecuteNonQuery();
if(k>0)
{
lable.text="Updated Successfully";
}
else
{
lable.text="Some Internal Error";
}
|
|
|
|
|
hi
i have written 3 different select query in mysql based on yesterday,today, tommorow dates to get the birthday details as follows
select concat(name,', ',title) as 'Yesterday 30-04-2014' from personal_details where DOB=curdate() - interval 1 day
select concat(name,', ',title) as 'Today 01-05-2014' from personal_details where DOB=DATE(NOW())
select concat(name,', ',title) as 'Tommorow 02-05-2014' from personal_details where DOB=curdate() + interval 1 day
how to join all 3 query results to one, i need to show as below
Yesterday Today Tomorrow
aaaa gggg nnnnn
bbbb hhhhh mmmm
dddd jjjjj
eeee
ffff
How to achieve this, i am not able to do.
If i tried with join there it wont match any condition and will not work because in each query result i will get unique values.
I tried with another query by putting as below
select a.* from (select CASE DOB WHEN (curdate() - interval 1 day) THEN concat(name,', ',title) ELSE '' END AS 'Yesterday', CASE DOB WHEN (DATE(NOW())) THEN concat(name,', ',title) ELSE '' END AS 'Today',CASE DOB WHEN (curdate() + interval 1 day) THEN concat(name,', ',title) ELSE '' END AS 'Tomorrow' from personal_details ) as a where a.Yesterday IS NOT NULL and a.Today IS NOT NULL and a.Tomorrow IS NOT NULL
It is showing the result like in all the three column some rows will be null
I dont want null values in any column. i want output as above.
How to achieve this. If anybody knows please reply me.
Thanks in advance.
|
|
|
|
|
This has nothing to do with .NET, so it should be posted in the Database forum.
Oh, wait. You already posted it there[^]. And received an answer.
9. Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So I have an app that is targeted to (compiled, built against) .NET 4.0
I have clients that have only .NET 3.5 installed.
They want to run my .NET 4.0 targeted app in their .NET 3.5 only environment.
I have tried adding the <supportedRuntime version="v2.0.50727" /> to the .config file but still get a runtime error on app initialization.
I suppose this makes sense, since I'm trying to run an app that's targeting a newer version on an older version.
Going the other way, targeting v3.5 and running in a v4.0 only environment works (with the supportedRuntime element).
So, am I right that you can't do what I want? That is run a 4.0 targeted app in a 3.5 only environment?
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
Is there a reason they cannot install .NET 4.0? (Is 4.0 Client sufficient?)
It happily co-exists side-by-side with .NET 3.5.
The only other suggestion is to rebuild the app targeting .NET 3.5 if possible.
The targeted environment is what it requires to run. Any other expectation is akin to expecting a MAC executable to run on Linux.
|
|
|
|
|
Because they don't want to. Which is reason enough I guess.
Matt T Heffron wrote: Any other expectation is akin to expecting a MAC executable to run on Linux. LOL. Yeah, that's what I figured.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
Try compiling it to 3.5.
You may be "targeting" 4.0, but if you didn't use any of the new 4.0 features ...
Unless you proactively checked what the new features were and then employed them, I doubt whether anyone made use of them (by accident).
|
|
|
|
|
Thanks, that's the conclusion I've come to.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
Hi ,
I looked back and forth for a free Library or Framework that allows me developing a program that generates a .ods spreadsheet file.
I used the AODL Library but there is a problem in precising the cells , it not organized at all .
I looked for Apache OpenOffice SDK , when I tried to run an example there was an error of architecture x86 compatibility and requires OpenOffice SDK 3.0 or in my project I'm working with .NET Framework 4.5 .
If there is a solution , I will be so thankful
Thank you in advance
Cheers,
|
|
|
|
|
|
Hi all ,
I am currently using Windows 8 as Operating System.
I created a Windows Service and then when I tried to start it , it pops up a message : Error 5 Access Denied : Windows can't start the service .
'Excuse me if the traduction of the error message isn't correct'
Thank you in advance for your help.
Cheers
|
|
|
|
|
File access problem maybe?
(It's been a while since I wrote a Windows Service.)
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
Hi ,
The problem is that the project worked fine in Windows 7 but switching to Windows 8 make this problem
|
|
|
|
|
It's still more likely a file access problem than an operating system problem.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
sifi mohamed amine wrote: when I tried to start it ,
What user was used on the Win 7 machine and what on the Win 8 machine?
|
|
|
|
|
Thanks for your response , I solved the problem by allowing sole security features.
|
|
|
|
|