In your question there is almost no information about the database, and it’s not so easy to copy the table from MS Office Word, as it seems to me, and then present it in the right form. For example, if there is a connection with the question that you asked about entering data from a table to the clipboard (where the delimiters are semicolons, and the lines are separated by a line break), you can give the following code:
using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string[] data = Clipboard.GetText().Split('\n'); for (int i = 0; i < data.Length; i++) data[i] = data[i].Remove(data[i].Length - 1, 1); // удаляем '\r' int lengthRow = 0; for (int i = 0; i < data[0].Length; i++) if (data[0].IndexOf(';', i) != -1) lengthRow++; string insertString = "insert into " + tableName + " values("; for (int i = 0; i < lengthRow; i++) insertString += "@" + (char)(i + 97) + ", "; // 97 - a, 98 - b и т.д. insertString = insertString.Remove(insertString.Length - 2, 2); // удаляем ", " из конца insertString += ");"; SqlCommand insertCommand = new SqlCommand(insertString, connection); for (int i = 0; i < data.Length; i++) { string[] values = data[i].Split(';'); insertCommand.Parameters.Clear(); for (int j = 0; j < lengthRow; j++) insertCommand.Parameters.AddWithValue("@" + (char)(i + 97), values[j]); insertCommand.ExecuteNonQuery(); } }
Once he coped with the task. Code on the rights of "IMHO", do not scold. Here I form the line "insert into% tableName% values ( @a , @b , ... @n );", then substituting specific values for @a , @b and other "variables".