"Format of the initialization string does not conform to specification starting at index 0."
"Format of the initialization string does not conform to specification starting at index 0."
我收到这个错误:
Format of the initialization string does not conform to specification
starting at index 0.
我的代码是:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Data.OleDb;
using System.Configuration;
namespace LibrarySystem
{
public partial class PIDD : Form
{
public PIDD()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
frmMed Med = new frmMed();
Med.Show();
var conn = new SqlConnection("ConnectionString");
//var command = new SqlCommand("Patient.dbo.P_ID", connection);
var command = new SqlCommand("SELECT P_ID FROM Patient WHERE id='" + textBox1.Text + "",connection);
connection.Open();
var reader = command.ExecuteReader();
if (reader.Read())
{
textBox1.Text = reader["id"].ToString();
}
else
{
// No entry found
}
connection.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
public SqlConnection connection { get; set; }
}
}
我正在尝试写入数据库中已存在的 ID,并检查 ID 是否正确,然后在下一个帧中显示它,
初始化字符串的格式不符合从索引 0 开始的规范。 只是一个 ArgumentException 消息,来自给 SqlConnection(string)
constructor: give it a valid SQL Server connection string 一个错误的连接字符串(即而不是 "ConnectionString"
),您将准备好继续处理代码中的其他问题。
作为参考,您可以看到我如何快速、最小地变形您的代码以确认 LINQPad 4 中给定错误消息的来源:
我收到这个错误:
Format of the initialization string does not conform to specification starting at index 0.
我的代码是:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Data.OleDb;
using System.Configuration;
namespace LibrarySystem
{
public partial class PIDD : Form
{
public PIDD()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
frmMed Med = new frmMed();
Med.Show();
var conn = new SqlConnection("ConnectionString");
//var command = new SqlCommand("Patient.dbo.P_ID", connection);
var command = new SqlCommand("SELECT P_ID FROM Patient WHERE id='" + textBox1.Text + "",connection);
connection.Open();
var reader = command.ExecuteReader();
if (reader.Read())
{
textBox1.Text = reader["id"].ToString();
}
else
{
// No entry found
}
connection.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
public SqlConnection connection { get; set; }
}
}
我正在尝试写入数据库中已存在的 ID,并检查 ID 是否正确,然后在下一个帧中显示它,
初始化字符串的格式不符合从索引 0 开始的规范。 只是一个 ArgumentException 消息,来自给 SqlConnection(string)
constructor: give it a valid SQL Server connection string 一个错误的连接字符串(即而不是 "ConnectionString"
),您将准备好继续处理代码中的其他问题。
作为参考,您可以看到我如何快速、最小地变形您的代码以确认 LINQPad 4 中给定错误消息的来源: