|
I learned PHP and VB from googling. Actually I learned PHP because a game named Tribes used the zend engine and I picked up a PHP book and realized I knew the syntax better than the book. Did PHP for 10 years and made some pretty impressive stuff.
I also did some stuff in VB that was pretty advanced. But I haven't done it in a few years (like, 4?)
Once you learn many of the basics of .net, all I have left is translating it into the syntax of c#, which IMO has better structure than VB, and a structure i'm more familiar with (logic and conditions like PHP, some variables like C++, which I took in high school)
I don't think I could relearn the VB crap. I'm used to &&, ||, if() foreach loops, all in PHP. One thing I didn't like is you can't do multiple logical comparisons in switch/case, but that it rarely used in PHP
|
|
|
|
|
actually this is throwing me an error. "Quote: Cannot implicitly convert type 'void' to 'System.Windows.Forms.DialogResult
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void Main_Load(object sender, EventArgs e)
{
if(!File.Exists(Directory.GetCurrentDirectory() + "\\Tracker.db"))
{
this.Enabled = false;
CreateDB dbForm = new CreateDB();
DialogResult res = dbForm.ShowDialog();
if (res == DialogResult.Cancel)
Application.Exit();
}
}
}
public partial class CreateDB : Form
{
public event EventHandler CancelPressed;
public CreateDB()
{
InitializeComponent();
}
private void Cancel_Click(object sender, EventArgs e)
{
if (CancelPressed != null)
CancelPressed(this, EventArgs.Empty);
}
}
|
|
|
|
|
|
private void Cancel_Click(object sender, EventArgs e)
{
return DialogResult.Cancel;
}
I returned a DialogResult now I get
Since 'TechTracker.CreateDB.Cancel_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression
and yeah I tried changing void to DialogResult and it gave me an error on the form
|
|
|
|
|
|
ok I get it, so I didn't even need cancel_click (this is a delegate, right?) at all since the DialogResult was already cancel in the form properties.
|
|
|
|
|
|
ok, been working on it, i'd figure i'd just add to this instead of making a new thread. I've been messing with SQLite.
What I want is to make a function to run the query, get row data and return it. Of course, rows are of mixed types, Using GetDataTypeName(), but storing these into an array is impossible because arrays can only be one type
is there a way to store the row data into an array? I've tried the reader row data itself, but i'm not sure i'm going about it the right way
this is the core section i'm trying. I've successfully done the query and got the data inside the function, just returning it is the problem
sqlite_cmd = sql_conn.CreateCommand();
sqlite_cmd.CommandText = sql_query;
sqlite_datareader = sqlite_cmd.ExecuteReader();
SQLLiteReader Row[];
for(int i = 0; sqlite_datareader.Read(); i++)
{
Row[i] = sqlite_datareader;
}
and return the row. I tried passing the reader up by reference but that was unsuccessful
My error:
Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
|
|
|
|
|
oh duh I needed to specify 'Array'
but now I get
Array SQLLiteReader Row[];
^^^
"; expected"
^
identifier expected
|
|
|
|
|
 wait a second I used this
DataTable returnTable = new DataTable();
DataColumn dtColumn;
DataRow dataRow;
MessageBox.Show(fieldCount.ToString());
for (int i = 0; i <= (fieldCount - 1); i++)
{
switch (sqlite_datareader.GetDataTypeName(i))
{
case "TEXT":
dtColumn = new DataColumn();
dtColumn.DataType = typeof(String);
dtColumn.ColumnName = sqlite_datareader.GetName(i);
returnTable.Columns.Add(dtColumn);
break;
case "INTEGER":
dtColumn = new DataColumn();
dtColumn.DataType = typeof(Int32);
dtColumn.ColumnName = sqlite_datareader.GetName(i);
returnTable.Columns.Add(dtColumn);
break;
}
}
for (int j = 0; sqlite_datareader.Read(); j++)
{
for (int k = 0; (k <= fieldCount - 1); k++)
{
MessageBox.Show(sqlite_datareader.GetDataTypeName(k));
MessageBox.Show(sqlite_datareader.GetName(k));
switch (sqlite_datareader.GetDataTypeName(k))
{
case "TEXT":
dataRow = returnTable.NewRow();
dataRow[sqlite_datareader.GetName(k)] = sqlite_datareader.GetString(k);
returnTable.Rows.Add(dataRow);
break;
case "INTEGER":
dataRow = returnTable.NewRow();
dataRow[sqlite_datareader.GetName(k)] = sqlite_datareader.GetInt32(k);
returnTable.Rows.Add(dataRow);
break;
}
}
*/
to try to load the query into a datatable (unsuccessfully, datatype problems), and you can just use .load()? That was a day well wasted
|
|
|
|
|
Hi I am using Entity Framework Code First to gnerate a table, its generating table correctly, but when I am querying it seems like its generating or asking for an extra column, which I didn't intend for.
Here is my Code First Entity Class
[Table("CaseAssignedToInvestigators")]
public class CaseAssignedToInvestigator
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CaseAssignedToInvestigatorsId { get; set; }
[Required]
[Index("IX_UniqueConstraintCaseAssignedToInvestigator", 1, IsUnique = true)]
public int CaseId { get; set; }
public Case Case { get; set; }
[Required]
[Index("IX_UniqueConstraintCaseAssignedToInvestigator", 2, IsUnique = true)]
[MaxLength (128)]
public string UserId { get; set; }
public ApplicationUser ApplicationUser { get; set; }
}
Its generating table properly, but when I queruing as below:
public IQueryable<T> GetAll()
{
return this.DbSet.AsQueryable();
}
This is generating a query with a column which doesn't exist, as below:
SELECT
[Extent1].[CaseAssignedToInvestigatorsId] AS [CaseAssignedToInvestigatorsId],
[Extent1].[CaseId] AS [CaseId],
[Extent1].[UserId] AS [UserId],
[Extent1].[ApplicationUser_Id] AS [ApplicationUser_Id]
FROM [dbo].[CaseAssignedToInvestigators] AS [Extent1]
Here [ApplicationUser_Id] is not a column I am intending for, how can I get rid of this, my migration script had it but I commented it out, any help please thanks in advance.
My migration file is as below:
public partial class CaseAssignedToInvestigator_AddPK : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.CaseAssignedToInvestigators",
c => new
{
CaseAssignedToInvestigatorsId = c.Int(nullable: false, identity: true),
CaseId = c.Int(nullable: false),
UserId = c.String(nullable: false, maxLength: 128)
})
.PrimaryKey(t => t.CaseAssignedToInvestigatorsId)
.ForeignKey("dbo.AspNetUsers", t => t.UserId)
.ForeignKey("dbo.Cases", t => t.CaseId, cascadeDelete: true)
.Index(t => new { t.CaseId, t.UserId }, unique: true, name: "IX_UniqueConstraintCaseAssignedToInvestigator");
}
public override void Down()
{
CreateTable(
"dbo.CaseAssignedToInvestigators",
c => new
{
CaseId = c.Int(nullable: false),
UserId = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => new { t.CaseId, t.UserId });
DropForeignKey("dbo.CaseAssignedToInvestigators", "CaseId", "dbo.Cases");
DropForeignKey("dbo.AspNetUsers", "Case_CaseId", "dbo.Cases");
DropIndex("dbo.CaseAssignedToInvestigators", "IX_UniqueConstraintCaseAssignedToInvestigator");
DropIndex("dbo.AspNetUsers", new[] { "Case_CaseId" });
DropColumn("dbo.AspNetUsers", "Case_CaseId");
DropTable("dbo.CaseAssignedToInvestigators");
CreateIndex("dbo.CaseAssignedToInvestigators", "UserId");
CreateIndex("dbo.CaseAssignedToInvestigators", "CaseId");
AddForeignKey("dbo.CaseAssignedToInvestigators", "UserId", "dbo.AspNetUsers", "Id", cascadeDelete: true);
AddForeignKey("dbo.CaseAssignedToInvestigators", "CaseId", "dbo.Cases", "CaseId", cascadeDelete: true);
}
}
All the commented out code in my migration script is not needed for me - any help would be much appreciated thanks in advance.
|
|
|
|
|
This is over my head, and I don't know c#. But when I deal with forms and tables, I tend to use .Visible=false on individual elements to hide them, yet have the data still exist to be referenced later. Not sure it can help you
|
|
|
|
|
The conventions don't understand that you wanted UserId to be the foreign-key column for the ApplicationUser navigation property.
As a result, EF assumes that UserId is just a standard string column, which is not connected to anything. It added the ApplicationUser_Id column to serve as the foreign-key link for the ApplicationUser navigation property.
Code First Conventions - EF6 | Microsoft Docs[^]
For the conventions to work, you'd either need to rename the UserId property to ApplicationUserId , or rename the ApplicationUser property to User .
If you can't rename either property, you need to use data annotations or the fluent API to configure your foreign key relationship correctly. For example:
[Required]
[Index("IX_UniqueConstraintCaseAssignedToInvestigator", 2, IsUnique = true)]
[MaxLength (128)]
[ForeignKey(nameof(ApplicationUser))]
public string UserId { get; set; }
public ApplicationUser ApplicationUser { get; set; } Or:
modelBuilder.Entity<CaseAssignedToInvestigator>()
.HasOne(case => case.ApplicationUser)
.WithMany()
.HasForeignKey(case => case.UserId);
Code First Data Annotations - EF6 | Microsoft Docs[^]
Fluent API - Relationships - EF6 | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
For VB.net 2008
So a program i've had in my head for a while, i've been thinking about how to go about retrieving data over the internet or even lan (securely)
mysql is a possibility, but dealing with the cert files on the client and lack of support for the connector is a pain (mainly due to no longer support for .net 2008, and I plan to make it strict .net 3.5 for compatability reasons)
What I did with one old, unrelated program was (.net 2005) was use PHP to feed XML over https (though it had no signing, I overrode that). This seemed to work fine, but i'm still not sure if this is the BEST way to go about it.
Really I think of the best ways would be PHP/MySQL/XML over lan, but I don't want to expose my scripts
any other ideas?
|
|
|
|
|
A "LAN" is not the same things as "the internet" in terms of a target audience.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
oh believe me I know.
But network (lan) traffic can still be intercepted, packet sniffed, and if unencrypted, exploited.
I'm now looking into possibly mysql over SSH. Disadvantage of course is the app must have the SSH username/password as program variables, which can be extracted. Vs direct MySQL, which you can just have a person login with their own mysql username and password. Is there any way to disassociate SSH with the filesystem/console and just mysql
is there any better way than using XML/SSH for over the internet (yes, not lan). As i'm still not sure if I should do this lan or internet.
This is a computer repair management software, i'm going to initially write it for myself, and maybe later release it, i'm not sure free or pay. If I use an internet web connector, I can enable a payment system for peoples accounts, but if thier internet is out, they can't use it. Lan, they can.
i'm also considering using studio 2012, as the mysql connector does not work in 2008 (says "system cannot find the reference specified")
and as much as i've learned vb.net a few years back, c#.net seems to be closer to PHP, my long learned language. Might consider learning c#
|
|
|
|
|
Hi. I want to implement a sending email service using .net core worker service. For doing that I use .net core 3 Worker service and in Worker class and I added NetCore.MailKit 2.0.2 to my project. I added the below lines of code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Mail;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic;
using MimeKit;
using MimeKit.Text;
namespace MyWorkerService
{
public class Worker : BackgroundService
{
private readonly ILogger<worker> _logger;
private HttpClient client;
public Worker(ILogger<worker> logger)
{
_logger = logger;
}
public override async Task StartAsync(CancellationToken cancellationToken)
{
var message = new MimeMessage();
message.To.Add(new MailboxAddress("Mike", "mike@gmail.com"));
message.From.Add(new MailboxAddress("Elen", "elen@gmail.com"));
message.Subject = "Hi";
message.Body = new TextPart(TextFormat.Html)
{
Text = "Email for testing"
};
//-----------------------------------------------------------
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);
//SMTP server authentication if needed
client.Authenticate("elen@gmail.com", "fava");
client.Send(message);
client.Disconnect(true);
}
}
public override async Task StopAsync(CancellationToken cancellationToken)
{
// DO YOUR STUFF HERE
await base.StopAsync(cancellationToken);
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(1000, stoppingToken);
}
}
}
}
And the program class is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace MyWorkerService
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseWindowsService()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<worker>();
});
}
}
I could created and deployed the service and when I start it, its status changes to running. Now my problem is, it doesn't send any email to the specified email address. I appreciate if anyone could solve my issue.
|
|
|
|
|
First, debug it and make sure the code works as is. Secondly, add logging so you can see what is happening.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Google is quite restrictive on the use of its SMTP server. Use your debugger to check exactly what happens inside the sending method.
|
|
|
|
|
NB: I hope that's not your real GMail username and password that you've just posted to a public forum?
If it is, you should change your password immediately, and review your account for any suspicious activity.
But I would hope that Google wouldn't let you use such an insecure password.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hey Guys,
I'm just trying my first steps in Entity Framework. My Database is a Maria with Version 10.4.x.
For connecting to DBMS I setup a Project with the EF6.
References:
- EntityFramework
- MySql.Data
- mysql.data.entity.EF6
- MySql.Data.EntityFramework
All versions are the newest Version of NUGET. (Working on VS2019)
When I want to generate the Data-Model (ADO.NET Entity Data Model) through the Project-Explorer, I get an Error:
"The Project references latest Version of EntityFramework; for Connection a compatible (for this version) Entity Framework-Databasedriver could not be found."
It seems to me that there is something missing... but what? Is there still a libirary missing?
Regards 
|
|
|
|
|
|
Excel.Application oExcel = new Excel.Application();
oExcel.Visible = true;
Excel.Workbooks oWorkbooks = oExcel.Workbooks;
string Pfad = "C:\test.xlsx";
Excel.Workbook oWorkbook = oWorkbooks.Open(Pfad);
Excel.Worksheet oSheet = oWorkbook.Sheets[1];
oSheet.Cells[1, 1] = "Test";
oSheet.SaveAs("C:\test.xlsx");
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.FinalReleaseComObject(oSheet);
oWorkbook.Close();
Marshal.FinalReleaseComObject(oWorkbook);
oExcel.Workbooks.Close();
Marshal.FinalReleaseComObject(oWorkbooks);
oExcel.Application.Quit();
Marshal.FinalReleaseComObject(oExcel);
oExcel = null;
Above code is not working on server. Office is not activated on server so this is reason to not closing it or any other issue, please help me to solve this problem
|
|
|
|
|
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
There are various ways to create or modify Excel spreadsheets on the server without using Office interop. For example:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello experienced people!!
I want to convert a data from text file to IList of X,Y,Z coordinates.
Actually i need to create topography in Autodesk Revit which needs Ilist of X,Y,Z coordinates. the text file which i am having i can manually directly feed into Revit and create topography as its X,Y,Z Coordinates. But using by c# coding in visual studio i need to convert it to Ilist of X,Y,Z coordinates to be ready as an input. Below is the text of my text file which is X,Y,Z separated by commas
609608.949,5641208.924,309
609609.283,5641208.227,309
609609.793,5641207.702,309
609610.469,5641206.828,309
609610.809,5641206.479,309
609611.318,5641205.954,309
609611.821,5641205.083,309
609612.496,5641204.212,309
609612.996,5641203.342,309
609613.664,5641202.299,309
609613.991,5641201.433,309
609614.149,5641200.741,309
609614.476,5641199.875,309
609614.637,5641199.357,309
609614.963,5641198.492,309
609615.115,5641197.630,309
609615.440,5641196.767,309
609615.596,5641196.077,309
609616.251,5641194.697,308.983
609616.407,5641194.008,308.977
609616.723,5641192.805,308.965
609617.043,5641191.946,308.952
609617.198,5641191.432,308.947
609617.508,5641190.232,308.935
609617.658,5641189.376,308.929
609617.812,5641188.691,308.923
Also i used this code line to access all lines of this text file as strings
List<string> lines = File.ReadAllLines(@"D:\My.txt").ToList();
|
|
|
|
|