我需要从windows窗体将连接详细信息添加到C#格式的数据源中
我需要在windows窗体中输入连接详细信息并将其添加到此字符串。您错过了正确的字符串连接。更好的解决办法是:我需要从windows窗体将连接详细信息添加到C#格式的数据源中,c#,sql-server-2008,windows-forms-designer,C#,Sql Server 2008,Windows Forms Designer,我需要在windows窗体中输入连接详细信息并将其添加到此字符串。您错过了正确的字符串连接。更好的解决办法是: String str="server= " + textBox1.Text ";database=" + textBox2.Text ";UID=" + textBox3.Text ";password="+ textBox4.Text ";"; 在新的c#功能中,您也可以使用 String.Format("server={0};database={1};UID={
String str="server= " + textBox1.Text ";database=" + textBox2.Text ";UID="
+ textBox3.Text ";password="+ textBox4.Text ";";
在新的c#功能中,您也可以使用
String.Format("server={0};database={1};UID={2};password={3};", textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
您不应该进行这种字符串操作。使用
$"server={textBox1.Text};database={textBox2.Text};UID={textBox3.Text};password={textBox4.Text};";