Click here to Skip to main content
15,391,695 members
Home / Discussions / C#
   

C#

 
GeneralRe: mysql delete code error Pin
OriginalGriff20-Mar-22 2:33
mveOriginalGriff20-Mar-22 2:33 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 2:46
MemberN Mohamed rafi20-Mar-22 2:46 
GeneralRe: mysql delete code error Pin
OriginalGriff20-Mar-22 3:26
mveOriginalGriff20-Mar-22 3:26 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 3:46
MemberN Mohamed rafi20-Mar-22 3:46 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 2:47
MemberN Mohamed rafi20-Mar-22 2:47 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 3:09
MemberN Mohamed rafi20-Mar-22 3:09 
GeneralRe: mysql delete code error Pin
Dave Kreskowiak20-Mar-22 4:51
mveDave Kreskowiak20-Mar-22 4:51 
GeneralConnection string Error VS to Mysql Pin
N Mohamed rafi18-Mar-22 20:32
MemberN Mohamed rafi18-Mar-22 20:32 
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();
}
}
GeneralRe: Connection string Error VS to Mysql Pin
OriginalGriff18-Mar-22 21:04
mveOriginalGriff18-Mar-22 21:04 
GeneralRe: Connection string Error VS to Mysql Pin
N Mohamed rafi18-Mar-22 21:08
MemberN Mohamed rafi18-Mar-22 21:08 
GeneralRe: Connection string Error VS to Mysql Pin
OriginalGriff18-Mar-22 21:17
mveOriginalGriff18-Mar-22 21:17 
GeneralRe: Connection string Error VS to Mysql Pin
N Mohamed rafi18-Mar-22 21:27
MemberN Mohamed rafi18-Mar-22 21:27 
GeneralRe: Connection string Error VS to Mysql Pin
OriginalGriff18-Mar-22 22:35
mveOriginalGriff18-Mar-22 22:35 
GeneralRe: Connection string Error VS to Mysql Pin
N Mohamed rafi18-Mar-22 22:51
MemberN Mohamed rafi18-Mar-22 22:51 
GeneralRe: Connection string Error VS to Mysql Pin
OriginalGriff18-Mar-22 23:07
mveOriginalGriff18-Mar-22 23:07 
GeneralRe: Connection string Error VS to Mysql Pin
N Mohamed rafi18-Mar-22 23:15
MemberN Mohamed rafi18-Mar-22 23:15 
GeneralRe: Connection string Error VS to Mysql Pin
OriginalGriff18-Mar-22 23:28
mveOriginalGriff18-Mar-22 23:28 
GeneralRe: Connection string Error VS to Mysql Pin
N Mohamed rafi19-Mar-22 0:36
MemberN Mohamed rafi19-Mar-22 0:36 
GeneralRe: Connection string Error VS to Mysql Pin
OriginalGriff19-Mar-22 1:14
mveOriginalGriff19-Mar-22 1:14 
GeneralRe: Connection string Error VS to Mysql Pin
Richard MacCutchan19-Mar-22 0:43
mveRichard MacCutchan19-Mar-22 0:43 
GeneralRe: Connection string Error VS to Mysql Pin
N Mohamed rafi19-Mar-22 2:07
MemberN Mohamed rafi19-Mar-22 2:07 
GeneralRe: Connection string Error VS to Mysql Pin
Richard MacCutchan19-Mar-22 2:24
mveRichard MacCutchan19-Mar-22 2:24 
QuestionGoogle Map Pin
Luis M. Rojas18-Mar-22 10:46
MemberLuis M. Rojas18-Mar-22 10:46 
AnswerRe: Google Map Pin
Luc Pattyn18-Mar-22 11:19
sitebuilderLuc Pattyn18-Mar-22 11:19 
AnswerRe: Google Map Pin
OriginalGriff18-Mar-22 21:06
mveOriginalGriff18-Mar-22 21:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.