|
Warning also showing that
CS0414: the field form1.ID is assigned but its value is never used
CS8618 Non nullable field adapt must contain non null value when exiting constructtor consider declaring the field as nullable
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
namespace Basic
{
public partial class Form1 : Form
{
MySqlDataAdapter adapt;
int ID = 0;
public Form1()
{
InitializeComponent();
DisplayData();
}
private void DisplayData()
{
string connectionString;
MySqlConnection cnn;
connectionString = @"Data Source=localhost;Initial Catalog=testDB;User ID=root;Password=mysql";
cnn = new MySqlConnection(connectionString);
DataTable dt = new DataTable();
adapt = new MySqlDataAdapter("select * from employee", cnn);
adapt.Fill(dt);
dataGridView1.DataSource = dt;
cnn.Open();
cnn.Close();
}
private void ClearData()
{
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
ID = 0;
}
|
|
|
|
|
You're not listening, and i'm not even entirely sure you even read entire replies to you. YOu're just looking for copy'n'paste code without any work on your part, that's where the problem lies.
Where did those "AND" clauses come from? They're not in the SQL statement I wrote, and they are not needed at all since an ID uniquely identifies records.
|
|
|
|
|
I want to insert table in db and make connection to mysql to vs.
Error for below code is:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Configuration.ConnectionStringSettingsCollection.this[string].get returned null.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using System.Threading.Tasks;
using System.Data.SqlClient;
private void button6_Click(object sender, EventArgs e)
{
string id = textBox6.Text;
string name = textBox7.Text;
string salary = textBox8.Text;
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
string query = "INSERT INTO employee VALUES(@employee_id, @employee_name, @employee_salary)";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Parameters.AddWithValue("@employee_id", id);
cmd.Parameters.AddWithValue("@employee_name", name);
cmd.Parameters.AddWithValue("@employee_salary", salary);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Error for below code is:
System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
private void button8_Click(object sender, EventArgs e)
{
{
string connetionString;
SqlConnection cnn;
connetionString = @"Data Source=LAPTOP-NDOAR92R;Initial Catalog=testDB;User ID=root;Password=mysql";
cnn = new SqlConnection(connetionString);
cnn.Open();
MessageBox.Show("Connection Open!");
cnn.Close();
}
}
|
|
|
|
|
Read the error message, it is not only explicit, it tells you what to do to fix it:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
This may help: Simple SQL Connection String Creation[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
ok sir please tell step procedure i am very new to it. i don't know to correct it please help me
modified 19-Mar-22 3:19am.
|
|
|
|
|
1) DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
2) How do you expect me to tell you that step by step, given that I can't see your screen, access your HDD, or have a browse around your network? Did you read the link I gave you?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I don't understand that link sir, please send some more article pages
|
|
|
|
|
What part did you not understand?
Let's take the instructions one by one...
Quote: Create an empty text file somewhere on your hard disk, called "myfile.udl".
Have you done that?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Created sir this is the location sir D:\Official\ASP.NET\Projects\Basic
After that what i have to do sir?
|
|
|
|
|
The link gives teh next instruction:
Quote: Double click the file, and the "Data Link Properties" dialog will open:
Did you do that?
Do you get where I am going with this? Or do I need to copy and paste the whole Tip sentence by sentence as a separate reply to check you have done it?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
ok sir data link properties opened and i clicked test connection it shows error like Test connection faile because of an error initializing provider invalid authorization specification
then what i have to do now sir?
|
|
|
|
|
Did you follow the instructions between "open the file" and "press the button"?
It's saying that the information you provided for that server / database is not valid: the login name, or password for example.
If you filled in the info from your existing connection string, then that's why that failed as well: you aren't authorised under that login.
We can't fix that, short of coming round to your place and typing on your keyboard - which would cost you a considerable amount of money in time, flights, hotels, taxis, expenses ...
So it's probably a good idea if you find out what your login info should be from the person who installed the DB!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
ok sir i will try with correct username pwd and get back you soon
|
|
|
|
|
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Brilliant utility, I could really have done with it yesterday.
|
|
|
|
|
In Datalink properties if i click server name refresh it shows empty only sir. how to bring that there i don't know sir. My userid password is userid is root and pwd is mysql but if i enter that it shows error sir on data link properties.
|
|
|
|
|
|
Hello,
I am trying this example(and others), but i got the same error on every example. Of course even the error message says: object se.... i do not know why and neither the answer.
On every example i see: the error is always in the same definition.
i am using vs studio 2019
GDirections direccion;
var RutasDireccion = GMapProviders.GoogleMap.GetDirections(out direccion, inicio, final, false, false, false, false, false);
GMapRoute RutaObtenida = new GMapRoute(direccion.Route, "Ruta ubicación");
GMapOverlay CapaRutas = new GMapOverlay("Capa de la ruta");
CapaRutas.Routes.Add(RutaObtenida);
gMapa.Overlays.Add(CapaRutas);
gMapa.Zoom = gMapa.Zoom + 1;
gMapa.Zoom = gMapa.Zoom - 1;
contadorIndicadoresRuta = 0;
trazarRuta = false;
button3.Enabled = true;
break;
|
|
|
|
|
direccion es nada!
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|
|
Hi,
I am using the TcpClient and I run Connect and then talk to a device on my network.. This works fine.
its something like 192.168.1.123. If my work VPN is connected.. Forticlient.. then the TCPClient Connect does not work. The VPN has a different network something like 10.230.x.x. So want to find out why this happens. If I disconnect the VPN it fixes.
The code is C# something like..
TcpClient client = new TcpClient();
client.Connect(ipaddress,port);
This creates an exception.. "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"..
|
|
|
|
|
This has nothing to do with your code. This is just how your VPN works.
When your corporate (I'm assuming) VPN starts up, for security reasons, you cannot have your network adapter sitting in both the 10.x and 192.168.x networks at the same time. Any traffic going through the network adapter is sent to the 10.x network.
You cannot bypass this.
|
|
|
|
|
Thanks that is handy to know.. so I will need to try to work out if the connection then is a VPN.. so I can inform the user that the tool will not work properly when connecting to the device.
More googling 
|
|
|
|
|
Hi!
When i run my code with a excel document with words in, it works, but at fast as i read a document with numbers only i get error on marked line in code.
if (c.DataType.Value == CellValues.SharedString)
and the error is:
An error occurred!!!: The object reference has not been specified to an instance of an object.
I have a little hard to see why this happends, hope on you experts!
using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(input, true))
{
WorkbookPart workbookPart = myDoc.WorkbookPart;
WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
SheetData sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
foreach (Row r in sheetData.Elements<Row>())
{
foreach (Cell c in r.Elements<Cell>())
{
string value = c.InnerText;
if (c.DataType.Value == CellValues.SharedString)
{
var stringTable = workbookPart.GetPartsOfType<SharedStringTablePart>()
.FirstOrDefault();
if (stringTable != null)
{
value = stringTable.SharedStringTable.ElementAt(int.Parse(value)).InnerText;
GenerateBarcodeFromExcel(value, output);
}
}
else
{
GenerateBarcodeFromExcel(c.CellValue.Text, output);
}
}
}
myDoc.Close();
|
|
|
|
|
Not all Cells are hard typed, only when you set the property on the cell explicitly.
Excel makes only strings SharedString by default.
So you need to check if the DataType property has been set, that is 'c.DataType != null '.
Cheers
If you can read this, you don't have WingDings installed
|
|
|
|